Desidero programmare il pulsante del mouse per mostrare/nascondere il Finder. Ho scritto il seguente AppleScript e legato al mio pulsante del mouse:AppleScript per l'applicazione in primo piano
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
Questo funziona, ma è piuttosto lento. Ci vogliono circa 2 secondi per funzionare.
Voglio che sia più veloce. Il primo blocco tell usa System Events per ottenere il nome dello script e nasconderlo. Esiste un modo più semplice/veloce per ottenere il nome dell'applicazione in primo piano prima dello che inizia lo script? (vale a dire l'applicazione attiva quando lo script è stato attivato)