Question

Is there a semi-universal mechanism by which to reveal files as selected in various *nix window managers via the command line? For example, in Windows I can say the following:

 explorer.exe /select,C:\TestDir\TestFile.txt

…and Explorer will reveal the file and select it for you. In OS X I can say the following:

 osascript -e 'Tell application "Finder" to reveal "MacHD:Users:myaccount:Desktop:filename.txt"'

…and it will do the same. My question is, is there any way to do the exact same thing (somewhat universally) in any of the various popular *nix flavors across window managers? Obviously "Open Containing Folder" is simple enough, but I want to go the extra step of actually opening it with the specific file selected. Any assistance is appreciated.

Best.

Was it helpful?

Solution

I don't about other file managers (other answers can add that) but for nautilus it's been recently fixed

This allows to call nautilus uri:///path/to/file from the command line to open uri:///path/to with file pre-selected.

OTHER TIPS

For OSX AppleScript works for all versions, but if you know you'll be dealing with 10.6 or later you'd be better served by using the -R option for "open". It's around 30 times faster.

open -R "/Volumes/Users/Desktop/file-to-open.txt"

For Linux Nautilus allows for direct calling of the file, a generic solution for GNOME (you won't find one for "Linux") is the "gnome-open" command, which currently could open the directory but won't highlight the file:

"gnome-open /tmp/file.txt"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top