如果Apple Script没有(或只是一个信息窗口),请打开一个新的Finder窗口?

时间:2017-01-16 02:13:29

标签: applescript finder

Apple Script中没有找到使用现有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窗口?

1 个答案:

答案 0 :(得分:0)

信息窗口不是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