¿Cómo podría ejecutar código(por ejemplo display dialog("test")
) usando AppleScript sólo si el "Buscador" de la Aplicación se encuentra actualmente en el foco activo.
Respuesta
¿Demasiados anuncios?Esto funcionará si el script se llama desde el Editor de secuencias de Comandos, como "se sale del camino", para comprobar la aplicación siguiente en la línea, pero no si se hace doble clic desde el Finder, como Buscador, a continuación, ser siempre el último en la 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
Dejar respuesta anterior aquí para la posteridad
Rejigged toda la respuesta después de haber leído las preguntas 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