2009-07-18 12 views
8

Finderを表示/非表示にするためにマウスボタンをプログラムしたいと思います。私は以下のAppleScriptを書いてマウスボタンにバインドしました:最前面のアプリケーションをターゲットとする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ブロックはシステムイベントを使用してスクリプトの名前を取得し、それを非表示にします。スクリプトが始まる前に、最前面のアプリケーションの名前を取得する簡単で簡単な方法がありますか?? (つまり、スクリプトがアクティブになったときにアクティブだったアプリケーション)

答えて

5

実行時間が遅い理由は、アプリケーションとしてAppleScriptを保存したためです。これによりアプリケーションPPCのみが作成され、Rosettaで実行する必要があります。 Application Bundleを選択すると、汎用アプリケーションが作成されます。

関連する問題