2009-07-18 6 views
8

Je veux programmer le bouton de ma souris pour afficher/masquer le Finder. J'ai écrit l'AppleScript suivant et l'ai lié à mon bouton de la souris:AppleScript pour cibler l'application frontale

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 

Cela fonctionne, mais est plutôt lent. Cela prend environ 2 secondes pour fonctionner.
Je veux que ce soit plus rapide. Le premier bloc tell utilise System Events pour obtenir le nom du script et le cacher. Y at-il un moyen plus facile/plus rapide d'obtenir le nom de l'application la plus à l'avant avant le script commence? (c'est-à-dire l'application qui était active lorsque le script a été activé)

Répondre

5

La raison de la durée d'exécution lente est que j'ai sauvegardé l'applescript en tant qu'application. Cela rend l'application PPC uniquement, elle doit donc fonctionner sous Rosetta. Si vous choisissez Application Bundle, l'application sera universelle.

Questions connexes