如何从特定文件夹中的python启动新的Finder窗口(或Win on Win).我正在寻找的行为相当于iTunes中的音轨上下文菜单中的"Show in Finder"链接,或者大多数其他程序都会想到它.
我目前使用PyQt构建的UI,我想添加一个菜单选项,如"显示日志文件夹"或类似的东西,它会弹出一个新的查找器窗口.
更新:
从katrielalex建议尝试subprocess.Popen("/System/Library/CoreServices/Finder.app")抛出和OSError: Permission denied.尝试通过双击启动Finder.app表示它已被OS X使用并且无法打开.
当然必须有一种方法来打开一个新的Finder窗口.
Ned*_*ily 13
对于OS X,您可以通过py-appscript使用Finder的Apple Events(AppleScript)界面:
>>> from appscript import *
>>> file_to_show = "/Applications/iTunes.app"
>>> app("Finder").reveal(mactypes.Alias(file_to_show).alias)
app(u'/System/Library/CoreServices/Finder.app').startup_disk.folders[u'Applications'].application_files[u'iTunes.app']
>>> # Finder window of "Applications" folder appears with iTunes selected
Run Code Online (Sandbox Code Playgroud)
编辑:
OS X 10.6上更简单的解决方案是使用命令的新-R(显示)选项open(请参阅参考资料man 1 open):
>>> import subprocess
>>> file_to_show = "/Applications/iTunes.app"
>>> subprocess.call(["open", "-R", file_to_show])
Run Code Online (Sandbox Code Playgroud)