2009-07-18 12 views
8

Quiero programar mi botón del ratón para mostrar/ocultar el Finder. Escribí el siguiente AppleScript y lo até al botón del mouse:AppleScript para apuntar aplicación en primer plano

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 

Esto funciona, pero es bastante lento. Tarda unos 2 segundos en ejecutarse.
que quieren que sea más rápido. El primer bloque tell utiliza System Events para obtener el nombre del script y ocultarlo. ¿Hay una manera más fácil/más rápido para obtener el nombre de la aplicación en primer plano antes se inicia la secuencia de comandos? (Es decir, la aplicación que estaba activa cuando se activó el guión)

Respuesta

5

La razón para el tiempo de ejecución es lenta que salvé la applescript como una aplicación. Esto hace que la aplicación solo PPC, por lo que debe ejecutarse bajo Rosetta. Si eliges Application Bundle, se convertirá en una aplicación universal.

Cuestiones relacionadas