Precedence Between Macro Groups?

I am trying to create slightly different behavior for a single macro used in one app versus all and to invoke using the same hotkey for the single-app and gloable-app macros. Is there a way for KM to look first at the app-specific macro group for the app you're working on and only if it doesn't find the hotkey in that group to then look at the global group and take the action automatically rather than giving a dropdown of options? My solution so far has been to use conditionals but 1) this feels clunky and hard to implement and 2) I've not found a way to use multiple conditionals (of the type if...else...elif...elif...), only if/else. I'm open to other creative approaches that streamline and automate the decision making whether using control statements or not.

Create a macro group that is available in all applications except the special single-app. Then the hotkey will not trigger a conflict palette.

CleanShot 2021-06-26 at 17.47.36@2x

1 Like

Thank you, Rolian. But if I've understood correctly, I'm not sure if that approach would scale and would require a lot of duplication. Here's a specific case:

  • I map a hotkey "cmd + shift + [" to a macro that generates this text "[]" in all text editors.
  • That macro lives in "text expansion" group and is among many text expansion macros available to all text editors.
  • I decide that for editor "X" which has more specialized functionality, I want the same command to instead type "[[]]". I want to use the same hotkey because of muscle memory and also because the hotkey is intuitive.
  • Now, I need to duplicate all the other text expansion macros for X, those I want to remain available to all apps, if I disable "X" from the Macro Group.

I'd of course just use a conditional to avoid duplication. But that gets tricky: there are going to be more exceptions for more apps and you end up with something hard manage.

My main objective is to be able to not have to "think" when I execute these commands and to my mind that requires some logical rules which may not be built into KM. If there is another way to think about or solve this problem -- using scripting or otherwise, please let me know.

That is easily managed by using the KM Switch or Case action, so you can provide for exceptions to a specific hotkey/typed string for specific apps.

For a single "exceptional"' macro, you'd have three groups:

  1. Global, where all text expansions other than the exception live
  2. Global except in Application A, where "cmd + shift + [" generates this text "[]"
  3. Specific to Application A, "cmd + shift + [" generates this text "[[]]"

But if you need to do this for many "exceptional" macros across many applications vs the "single macro" you alluded to in your orignal post, then i agree this solution won't scale well

Thank you -- this is probably the best approach but I struggle with the interface and all the mouse clicks. Is there another way to achieve this using scripting that KM can then execute-- Is that documented anywhere? Or an approach outside of KM that can do this?

I don't understand the issue. The KM Switch case is very simple:

For example, here is a template I have saved to my KMFAM library:

image

JavaScript does offer a Switch command, but then you have all of the extra statements to get KM data into and out of a JXA Execute Script.

image

Before you reject an idea out of hand, you might give it a try to see how it actually works.

2 Likes

Thank you JMichaelTX for the suggestions and I'll give your switch template a try. My hesitation was that I'll have a number of exceptions to handle that would require conditional logic and the graphical input can get tedious. But your point is well taken to try first and see if it meets the needs before pursuing alternatives. Its great to have the JS option as a fallback: I could see that scaling nicely.