I originally tried using tell application "System Events" to set frontApp to name of first application process whose frontmost is true
to define the frontApp variable, but when I run just this script from KM the result displayed is firefox
, which is why I then tried using KM to define the varable instead (the result of which is Firefox
). Both methods of defining the variable result in the same error when running the full script in the macro. However, Script Editor executes the script as expected when passing the frontApp variable defined in KM.
The full script
tell application "Keyboard Maestro Engine"
set windowNamed to getvariable "Search"
-- set frontApp to getvariable "frontApp"
end tell
tell application "System Events" to set frontApp to name of first application process whose frontmost is true
tell application frontApp
if window windowNamed is miniaturized then
set miniaturized of window windowNamed to false
else
return
end if
end tell
If I hardcode the application to be "Firefox"
then the script executes as expected when running the macro with the script. I'm wondering if this is a quotation mark issue because when executing just tell application "System Events" to set frontApp to name of first application process whose frontmost is true
from Script Editor the result is "Script Editor"
(with quotes), but the KM results lack the quotation marks. I tried adding quotation marks to the KM variable, but, while the script executed, I don't understand what it did because it launched a dialogue box to select an application...
Even though it's working with the hardcoded application name, I'd much rather a general solution to this because I regularly use three different browsers. I expect I'm missing something painfully obvious, but I just can't seem to figure it out.