Maybe this is beating the a dead horse, but os.getcwd() returns the actual directory of the selected node - verified by test. It is as if when a node is selected, Leo changes the current directory to the path for that node. That would explain why "." works as well.
I don't know if this behavior was intended, but it makes some things convenient. For example if you have a file or script that wants to save something - maybe an image file it generated - then it will go into the *@path* directory for that node instead of into Leo's home directory (or wherever the outline exists). I now realize that I have made use of that behavior without realizing that it might have been different. On Tuesday, April 6, 2021 at 10:40:58 PM UTC-4 [email protected] wrote: > OK, after some more testing and thought: > > 1. Edward's example can't work as claimed, even if '.' is replaced by > *path*. The expression for *path* returns a path that a) has forward > slashes and won't work in Windows when you open explorer on it - confirmed > by test with both a console and in Leo - and 2) If the node contains an > external file, the *path *is to that file and so Explorer wouldn't get > opened on its directory anyway. Instead, the system's default program for > that file type will be invoked by Explorer. > 2. By actual test, I get the same result whether I comment *path* out or > not. > 3. If I do replace "." with *path*, explorer opens but not at the > intended directory because of the forward slashes in *path*. > > So to make it work in Windows, we have to 1) fix the path separators, and > 2) test whether the path is to a file or directory, and if it's a file then > find its parent directory. > On Tuesday, April 6, 2021 at 5:58:43 PM UTC-4 [email protected] wrote: > >> But in your snippet, you also use "." without (apparently) changing it. >> >> import os >> from subprocess import run >> path = g.fullPath(c, p) or os.path.abspath('.') >> >> cmd = ['explorer.exe', '.'] >> run(cmd) >> >> How is that supposed to work? Wouldn't you want to use *path* instead >> of "."? >> On Tuesday, April 6, 2021 at 5:18:14 PM UTC-4 [email protected] wrote: >> >>> But I suppose it would be better to use a more comprehensive method in >>> case you accidentally delete this "feature" in the future. >>> >>> On Tuesday, April 6, 2021 at 5:16:54 PM UTC-4 [email protected] wrote: >>> >>>> Well, it's more than that. Using "." works for @path subtrees that are >>>> not even on the same drive (that is, Windows drive) as the leo outline >>>> they >>>> are in. It's not just that "." sends you to the directory, say for the >>>> workbook in *%USERPROFILE%\.leo* (Windows). In the workbook outline >>>> at that location, for any of the following nodes begin selected, the >>>> command(s) go to the right directory: >>>> >>>> - head >>>> - @path d:\temp >>>> @path dir_1 >>>> @path dir_2 >>>> @clean test.txt >>>> >>>> On Tuesday, April 6, 2021 at 4:14:46 PM UTC-4 Edward K. Ream wrote: >>>> >>>>> On Tue, Apr 6, 2021 at 10:29 AM [email protected] <[email protected]> >>>>> wrote: >>>>> >>>>>> >>>>>> >>>>>> On Tuesday, April 6, 2021 at 10:14:19 AM UTC-4 Edward K. Ream wrote: >>>>>> >>>>>>> On Tue, Apr 6, 2021 at 7:15 AM [email protected] <[email protected]> >>>>>>> wrote: >>>>>>> >>>>>>> BTW, I have put a button into MyLeoSettings.leo that will open a >>>>>>>> file manager window (File Explorer on Windows) at the current >>>>>>>> directory of >>>>>>>> the selected node, whatever it is. This has been awfully handy. >>>>>>>> >>>>>>> >>>>>>> Great idea. However, I don't understand how '.' gets bound to the >>>>>>> directory of the selected node. Here is tested code for Windows that >>>>>>> works >>>>>>> as I expect. >>>>>>> >>>>>> >>>>>> I don't understand it either, but it works as I showed on both Linux >>>>>> and Windows. Sure makes for simple code! These commands have worked >>>>>> this >>>>>> way for a long time (years). A great undocumented feature! >>>>>> >>>>> >>>>> I strongly suspect that the code works by accident because loading a >>>>> .leo file effectively changes ".". But outlines like LeoPyRef.leo >>>>> contains >>>>> files in several directories. There is no way the OS can know how to >>>>> relate >>>>> '.' to the various directories. >>>>> >>>>> In short, I would recommend my code ;-) >>>>> >>>>> Edward >>>>> >>>> -- You received this message because you are subscribed to the Google Groups "leo-editor" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/leo-editor/b5daca55-75a1-4bf8-bdb4-c5fa62c18272n%40googlegroups.com.
