我正在使用以下applescript
重新启动查找器应用程序。
osascript -e "tell application \"Finder\"" -e "delay 1" -e "try" -e "quit" -e "delay 1" -e "activate" -e "end try" -e "end tell"
但有时此脚本不会重新启动查找器应用程序(仅退出查找器应用程序)。我在控制台中没有收到任何错误。
http://www.cocoabuilder.com/archive/cocoa/113654-nsapplescript-buggy.html
有人可以帮我吗?
这是一个苹果脚本的方式。正如您所看到的,您不能依赖特定的延迟时间。因此,我们通过检查 Finder 是否在正在运行的进程列表中来手动等待 Finder 退出。当它不再出现在列表中时,我们就知道它已经退出,我们可以再次激活它。
您还会注意到,由于重复循环,我在脚本中进行了时间检查。为了防止出现问题,我们不希望重复循环永远运行。因此,如果它运行超过 10 秒,我们会自动退出重复循环。
tell application "Finder" to quit
set inTime to current date
repeat
tell application "System Events"
if "Finder" is not in (get name of processes) then exit repeat
end tell
if (current date) - inTime is greater than 10 then exit repeat
delay 0.2
end repeat
tell application "Finder" to activate
这是该代码的 osascript 版本。
/usr/bin/osascript -e 'tell application "Finder" to quit' -e 'set inTime to current date' -e 'repeat' -e 'tell application "System Events"' -e 'if "Finder" is not in (get name of processes) then exit repeat' -e 'end tell' -e 'if (current date) - inTime is greater than 10 then exit repeat' -e 'delay 0.2' -e 'end repeat' -e 'tell application "Finder" to activate'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)