Creating "toggle" macros where it alternates between two sets of different actions from the same key?

I have a few programs where I believe they should have logically combined an action into one keyboard shortcut, creating basically a toggle on/off behavior. Instead, for this same on/off behavior, you have to remember two separate shortcuts entirely.

I was thinking of consolidating them simply to be run by a single master shortcut (using one hot key). So the first time I press that key, it activates the first action/shortcut, and the next time I press that key, it runs the second one.

This would also be handy for a few macros I wish to create which involve multiple actions, but each time I press that key I basically want them to run either in reverse or a separate string of actions - effectively creating a switch from on/off.

For you to visualize what I mean, I have these two sets of actions right now, all just a short sequence of keyboard shortcuts which is for something inside Adobe After Effects.

The first time I hit the key I would like to activate this sequence:

The next time I hit that same key, I would like to instead activate this sequence:

You can see from this they are pretty similar, the only difference beeing that final keystroke. If anyone is familiar with AE, basically the action here is that I'm trying to toggle a composition between full and low-resolution, something I do very frequently, so rather than use different keys for this, I'd rather treat it like an on/off switch from one key.

Also I believe in order for this to work correctly too that KM would need to store or remember the previously used state - as long as both programs are still open, even if press the key again an hour later, it should still remember where it left off in this sequence, so it doesn't accidentally start the sequence over. Thank you!

I do this kind of thing a lot but I rely on logic to determine which branch of the macro to run so I don't have to remember or save a state.

In this case, I'd look for some place (perhaps in a menu or via a scripting query) in which the resolution was reported and branch to the final action based on that. So you'd have your first two actions as they are followed by an If action that checks for resolution and executes one of those third actions if true and the other if false.

Same hot key, but let the code figure out what to do based on the current resolution.

1 Like

Hi, thanks for your response. I'm not the most technical person about scripting, although I have previously created the occasional macro which has involved logical statements and scanning the screen for a button or text. My only issue taking that approach is I have found that only seems to work well when the text or button in question resides in the same general area at all times. In this particular case with After Effects, all day long I'm resizing the timeline and opening/closing different panels, so the menu selection for resolution will be in an unpredictable place for KM to recognize, I think so anyway.

The other scenario may involve something which is never visible on the screen (the program hides the functionality under the hood only via keyboard shortcut for example). I also do a bit of music stuff in Logic and Cubase, and those programs have a few tools which really could've been consolidated into a toggle shortcut - no idea why the developers thought to assign such things to separate shortcuts, when the functionality is simply A or B, on or off.

In cases such as these, what I would want to do is simply consolidate them within KM from one shortcut - and then from within that it toggles back and forth. However there is nothing visually on the screen to feed into a logical operation using the methods I'm aware of (scanning for text, menu options, or a button). Hope that makes sense.

Don't overlook this bit of @mrpasini's reply:

Are there menus that are different when you're in one mode versus the other? If so, then you could use KM's ability to act based on menu conditions to control what happens.


yes, sorry I wasn't clear, what I meant from above is that I am familiar with using logic for the following action options within KM:

  • select menu by name
  • select or show menu item
  • press a button
  • find image

I've used some of these in the past. However there's a couple things such as with Cubase which are not directly accessible by the menu (or a button), and can only be accessed via shortcut, hidden "under the hood" as it were. I'll have to poke around for example but was basically just wondering if I know the shortcut for both options, would there be no way of having KM do one or the other if the last one was already previously done?

If there's no other way to tell what "mode" the app is in, then I think you'd have to use a global variable. Check to see if it's "1" before the choices begin; if it's not, do option #1 and set the global to "1". Set the "else" option to do the other thing, and in that section, either delete the global or set it to "0" or "2" or whatever.


1 Like

It's not that the options you want are available in the menus, but that there's something particular about the available menu items depending on which "mode" you are currently in. You might have different options in the "Edit" or "View" menus, for example.

You can use a global to keep track of state as @griffman describes but, sooner or later, it will go out of phase and you'll be doing the wrong thing in the wrong mode. Easy to reset and not so bad if you are just toggling between obviously different modes or views, but be careful if changing between eg "destructive" and "non-destructive" modes.

1 Like

Oh, I never hunt for an image on the screen. Try this:

Your example reference After Effects' resolution setting which has a menu bar equivalent (Adobe does that):

So, it seems, what you want is to know if Full or Quarter (or something else) is selected. You check that in your If action (as a Menu condition) and then either Select Menu Item or issue your keystroke, whatever you prefer.

I don't have After Effects installed (because I'm a simple guy) or I'd whip this up for you.

1 Like

No worries, I can figure this one out, thank you for that!

I can't remember off the top of my head the other scenarios I've run into previously where the option is unavailable via menu (this has come up for me here and there in Cubase or Logic). Next time it comes up I'll be sure to report back here with more specifics so we can find a solution.

Good point. Fortunately the functions I have in mind are mostly UI toggling behaviors, like opening specific panels or showing tools on/off. For example Steinberg who makes Cubase decided to use two separate keyboard shortcuts for the function to "show: automation" and "hide: automation" – if that term doesn't make sense to you the point is this function would never be both, it's either/or, like a switch, so having it toggle from one key would've made a lot more sense. Unfortunately I can't fix this within the program as I've tried.

So what I'm looking for wouldn't really have a destructive impact on what I'm doing if it were to go out of phase, it would just be mildly confusing and annoying at worst haha. But I will try the other suggested solutions first to see where I can get this.