Applescript 如果没有Apple脚本(或只有信息窗口),请打开新的查找窗口?

Applescript 如果没有Apple脚本(或只有信息窗口),请打开新的查找窗口?,applescript,finder,Applescript,Finder,在Apple脚本中,我发现使用现有查找窗口或打开新窗口的解决方案都不是故障安全的。大多数情况下,这是建议 tell application "Finder" if not (exists window 1) then make new Finder window end if end tell 这样,如果有一个信息窗口打开,代码不会打开一个“正常”的查找窗口。信息窗口(例如,通过“获取信息”打开)也是一个查找窗口,它不能处理以下类似于“正常”查找窗口的调用: t

在Apple脚本中,我发现使用现有查找窗口或打开新窗口的解决方案都不是故障安全的。大多数情况下,这是建议

tell application "Finder"
    if not (exists window 1) then
        make new Finder window
    end if
end tell
这样,如果有一个信息窗口打开,代码不会打开一个“正常”的查找窗口。信息窗口(例如,通过“获取信息”打开)也是一个查找窗口,它不能处理以下类似于“正常”查找窗口的调用:

tell application "Finder"
    set the target of the front Finder window to folder thePath
end tell

如果没有“正常”查找窗口,如何编写脚本以打开新的“正常”查找窗口?

在Apple脚本中,信息窗口不是查找窗口。“如果不存在(窗口1)…”条件应说明您正在寻找查找窗口:

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