But, I can't figure out why I sometimes have to key (trigger) it multiple times to show an app. It always works, but sometimes I have to key it twice. I know there must be a reason for this, and I've tried to figure it out but can't.
I'm trying to figure out a if there's something I can add or change that would prevent it from having to be triggered twice. Can anyone tell me?
The macro should work fine as long as that is the only way you ever activate/deactivate the applications.
But if you were, for example, to run the macro the hide Spotify, and then you were to launch Spotify manually in the Finder, the macro still thinks the app is in the Hidden state.
Similarly, if you use the macro to Activate Spotify, and then you manually quit Spotify, then the next time you run the macro it will “Hide” the already quit Spotify, and then the you trigger the macro again and then it will activate Spotify.
Note too, that the macro state will remain even if you restarted.
You could potentially add other macros like one that uses the Application trigger to detect Spotify being activated and set the variable holding the state to Activated at that point, and another that detected Spotify being quit and set the variable state to Hidden.
Multiple apps within the same macro, or multiple macros with one per app? If it's the first you'll need some logic for what to do when some are visible and some are hidden...
As well as @peternlewis's suggestion of "better variable maintenance", you could test for current app state and act accordingly. While you can't do that directly with a KM action you can use AppleScript. Here's an example set up for TextEdit, that also contains a disabled action for getting an app's "bundle ID":
I have to say that I'm not personally a fan of "toggling" in this situation -- after all, I either want to see the app(s) or I want to hide them, and their current state doesn't really matter. So I'd tend to a single macro with two hot key triggers that differ by a single modifier -- in this case, triggering without ⇧ shows the app(s), but with ⇧ included it hides them:
Ahh. I understand. I think that explains precisely what's happening, then. Thanks, Peter!
So, perhaps that macro is not the best way to accomplish what I was trying to do. There are a few apps (like spotify, messages, etc) that I need to open momentarily, but then I want them out of the way until I need them again, momentarily. That's what I was trying to accomplish, but I see there's probably a slightly better way to do that. It may be beyond my understanding and capabilities.
So simple. Could it really be that simple? That approach seems to work perfectly for my use case. I feel dumb. I was severely overcomplicating things. Thanks so much for your quick help!