これがアップルスクリプトの方法です。これまで見てきたように、特定の遅延時間に依存することはできません。したがって、実行中のプロセスのリストにあるかどうかを確認して、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'