¿Cómo podría ejecutar el código (por ejemplo display dialog("test")
) usando AppleScript solo si la aplicación "Finder" está actualmente enfocada/activa?
Esto funcionará si se llama a la secuencia de comandos desde el Editor de secuencias de comandos, ya que "se quita del camino" para verificar la siguiente aplicación en línea, pero fallará si se hace doble clic desde Finder, ya que Finder siempre será el último en línea.
tell application "System Events"
set frontmostProcess to first process where it is frontmost
set visible of frontmostProcess to false
repeat while (frontmostProcess is frontmost)
delay 0.2
end repeat
set secondFrontmost to name of first process where it is frontmost
set frontmost of frontmostProcess to true
end tell
tell application (path to frontmost application as text)
if "Finder" is in secondFrontmost then
display dialog ("Finder was last in front")
else
display dialog (secondFrontmost & " was last in front")
end if
end tell
Dejando aquí la respuesta anterior para la posteridad.
Rejugué toda la respuesta después de no haber leído la pregunta correctamente inicialmente ;-)
tell application "System Events"
set activeApp to name of first application process whose frontmost is true
if "Finder" is in activeApp then
display dialog ("test")
else
display dialog ("test2")
end if
end tell
display dialog (activeApp)
para confirmar exactamente lo que el script cree que es lo primero.tell application "app_name"
) difieren de los nombres de sus procesos (p. ej., set frontmost of process "app_process" to true
).
Kent
Guillermo
Tetsujin
Guillermo
Tetsujin
Guillermo
Tetsujin
Guillermo
key code (insert code here)
funciona, pero no se puede saber de antemano en qué aplicación se centra.Guillermo
Tetsujin
Guillermo
Tetsujin
Guillermo
Tetsujin
Guillermo