我发现Apple Script中没有使用现有Finder窗口或打开新Finder窗口的解决方案都是安全的。通常建议
tell application "Finder"
if not (exists window 1) then
make new Finder window
end if
end tell
这样,如果有一个信息窗口打开,则代码不会打开“普通” Finder窗口。信息窗口(例如,通过“获取信息”打开的窗口)也是Finder窗口,它不能处理以下用于“普通” Finder窗口的调用:
tell application "Finder"
set the target of the front Finder window to folder thePath
end tell
如果没有“普通” Finder窗口,我该如何编写脚本来打开新的“普通” Finder窗口?
信息窗口不是Apple Script中的Finder窗口。条件“如果没有(存在窗口1)...”应提及您正在寻找Finder窗口:
if not (exists Finder window 1) then
所以您忘了在窗口前面添加“ Finder”。另外,当没有打开或最小化所有窗口时,您可以打开一个新的Finder窗口:
tell application "Finder"
if not (exists Finder window 1) or (get collapsed of the front Finder window) then
make new Finder window
end if
set thePath to POSIX file /your/path/to/show
set the target of the front Finder window to folder thePath
activate
end tell
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句