Finder を表示/非表示にするようにマウス ボタンをプログラムしたいと考えています。次の AppleScript を作成し、マウス ボタンにバインドしました。
tell application "System Events"
--When this script is run,
-- the frontmost application will be this script itself
--Get the name of this script as it is running and hide it,
-- so that the previous frontmost application is in front again
set theName to name of the first process whose frontmost is true
set visible of process theName to false
set theName to name of the first process whose frontmost is true
end tell
if theName is "Finder" then
tell application "System Events"
set visible of process "Finder" to false
end tell
else
tell application "Finder"
activate
end tell
end if
これは機能しますが、かなり遅いです。実行には約 2 秒かかります。
もっと速くしたい。最初の Tell ブロックは、システム イベントを使用してスクリプトの名前を取得し、それを非表示にします。スクリプトが開始する前に最前面のアプリケーションの名前を取得する簡単で高速な方法はありますか? (つまり、スクリプトがアクティブ化されたときにアクティブだったアプリケーション)