Help With Simple Toggle Hide/Activate Apps Macro

This macro, created by @JMichaelTX:

https://forum.keyboardmaestro.com/uploads/default/original/3X/0/e/0e2897bafd4ac5c24ab1c39e23004f7303cf5a94.kmmacros

Here's my implementation of it:

I use this macro to show/hide multiple apps.

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?

Any tips would be greatly appreciated. Thanks!

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.

1 Like

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":

Toggle App Visibility.kmmacros (7.2 KB)

Image

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:

Hide:Show App(s).kmmacros (3.3 KB)

Image

1 Like

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. :blush:

Btw, I LOVE Keyboard Maestro!

2 Likes

For PCalc, I use a hot key triggered macro with this action:

image

The hot key will activate it, or if it is currently active, will hide it.

3 Likes

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!

3 Likes

Most everyone does just that (or just the reverse), before they develop a reasonable level of familiarity with and understanding of Keyboard Maestro.

I've been using Keyboard Maestro at a super-user level for about 17 years now, and I still don't know everything (or remember everything) about it.

:sunglasses:

  • Take your time.
  • Learn the terminology.
  • Look through all the menus in the Keyboard Maestro Editor very carefully
    • You won't remember everything but you'll begin to build your mind map of Keyboard Maestro.
  • Look through the Keyboard Maestro Editor's Preferences Panel very carefully.
  • Look through the Actions Panel (Cmd-K), and familiarize yourself with all the categories.
  • Use the Help in the Keyboard Maestro Editor
    • Option-Key in menus.
    • Help link in dialogs.
    • Use the search field in the Help Menu.
  • Use the Insert By Name functions in the Edit menu
    • Actions
    • Tokens
    • Functions
    • Variables
    • Dates
  • Don't spend more than 30 minutes banging your head against a problem.
    • The world has enough dain brammage already.
    • Search the KM Wiki.
    • Search the forum.
    • If you don't find answers pretty quickly then ask.

Your adventure has only just begun...

-Chris

5 Likes

Sorry for this delayed response. Thanks for the encouragement and advice, @ccstone! I appreciate.

1 Like