I have a macro that "launches" (activates) Stream Deck.app when the Stream Deck USB device is attached. Activating the app brings it to the front, and I would like to dismiss it and return to the previously active app. No matter the approach, it seems I have to insert a hard Pause between activating Stream Deck.app and returning to the previously active app for it to work. "Pause Until...This application is running" does not work - Stream Deck.app stays active. A Pause for 1.5 seconds seems to work, but anything less is inconsistent. Here is what I have:
BTW, I also tried using "Activate Last Application" instead of using a variable, but that also requires a hard Pause and it doesn't seem to recognize Keyboard Maestro as the last application so it skips to the last active application before Keyboard Maestro.
So my question is, why doesn't "Pause Until...This application is running" not work?
@ccstone - Thanks. I will keep that in mind for other scenarios because I have run into this before. In this case, I don't know the terminology, but the app doesn't behave like a typical app. No standard menu items. When it is active, the menubar from the previous app still shows.
@JMichaelTX - I did try that as well, which usually works, but not here. Keyboard Maestro can tell when it is running
Grrf... I dislike when applications fail to follow normal design guidelines (within reason).
Okay, the next thing I'd try is a Pause Until action using the 'Found Image' option.
If I had my hands on the Stream Deck app I'd also look at it with UI Browser to see if there were any UI elements I could find and wait to become active.
In lieu of that you could try my window analysis tool:
Hey those are some good ideas to approach this. Unfortunately, Stream Deck does not respond to Hide. I've tried it with AppleScript, ⌘H, Keyboard Maestro Hide action, and those command line options you shared. I thought -g might do the trick, but no.
So far, checking for the UI element as @ccstone suggested is the only thing that has worked. The way I posted above using AS is the best I could come up with.
I put that script into Execute Script action in place of the AppleScript and the Pause Until stuff. It worked, but the macro keeps running for some reason so I am going to stick with what I had. Thank you!
That did it. I marked the shell script as the solution.
Just an FYI: for whatever reason, If I quit the app and trigger the macro manually, I don't even see Stream Deck app. It just shows up in the menu bar. If I let the USB device trigger fire the same macro, the app appears in the front, then gets pushed back behind the previously active app.
Not complaining Just an observation. Thanks for the solution.
Note – your macro activates with the 'all windows' option.
Try unchecking that option and see what happens.
Another thing to try is this:
tell application "Stream Deck"
run
end tell
Another possibility:
use AppleScript version "2.4" --» Yosemite or later
use framework "Foundation"
use scripting additions
set appBundleID to "com.apple.TextEdit"
set ws to current application's NSWorkspace's sharedWorkspace()
set appURL to ws's URLForApplicationWithBundleIdentifier:appBundleID
set appAlias to appURL as alias
tell application "Finder" to open appAlias
There is not enough information to investigate whether there is any kind of bug. But as noted, some apps like this don't really quit, they turn themselves from background-only to foreground, and so “is running” may not mean what people think it means, and activating may or may not do what you expect.