如何将文件显示为“选定”从命令行在 *nix 中?
是否有一种半通用机制可以通过命令行显示在各种 *nix 窗口管理器中选择的文件?例如,在 Windows 中,我可以说以下内容:
explorer.exe /select,C:\TestDir\TestFile.txt
……资源管理器将显示该文件并为您选择它。在 OS XI 中可以说以下内容:
osascript -e 'Tell application "Finder" to reveal "MacHD:Users:myaccount:Desktop:filename.txt"'
……并且它也会做同样的事情。我的问题是,有没有办法在窗口管理器中的各种流行的 *nix 风格中做完全相同的事情(有点普遍)?显然“打开包含的文件夹”足够简单,但我想采取额外的步骤,使用所选的特定文件实际打开它。如有任何帮助,我们将不胜感激。
最好的。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不关心其他文件管理器(其他答案可以添加),但对于 nautilus 最近已修复
I don't about other file managers (other answers can add that) but for nautilus it's been recently fixed
对于 OSX,AppleScript 适用于所有版本,但如果您知道您将使用 10.6 或更高版本,则最好使用 -R 选项来表示“打开”。速度快了大约 30 倍。
open -R "/Volumes/Users/Desktop/file-to-open.txt"
对于 Linux,Nautilus 允许直接调用文件,GNOME 的通用解决方案(您不会找到“Linux”的解决方案)是“ gnome-open”命令,当前可以打开目录但不会突出显示文件:
“gnome-open /tmp/file.txt”
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"