Wie kann ich Code (z. B. display dialog("test")
) mit AppleScript nur ausführen, wenn die Anwendung "Finder" derzeit im Fokus / aktiv ist.
Dies funktioniert, wenn das Skript vom Skripteditor aus aufgerufen wird, da es "aus dem Weg geht", um die nächste App in der Reihe zu überprüfen, aber fehlschlägt, wenn es vom Finder aus doppelt angeklickt wird, da der Finder dann immer das letzte in der Reihe ist.
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
Lassen Sie die vorherige Antwort hier für die Nachwelt
Gesamte Antwort neu ausgerichtet, nachdem ich die Frage anfangs nicht richtig gelesen hatte ;-)
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)
, um genau zu bestätigen, was das Skript für den vordersten hält.tell application "app_name"
) unterscheiden sich von ihren Prozessnamen (z . B. set frontmost of process "app_process" to true
).
Kent
Wilhelm
Tetsujin
Wilhelm
Tetsujin
Wilhelm
Tetsujin
Wilhelm
key code (insert code here)
funktioniert, aber Sie können nicht im Voraus wissen, welche Anwendung fokussiert wird.Wilhelm
Tetsujin
Wilhelm
Tetsujin
Wilhelm
Tetsujin
Wilhelm