I have a macro that calls other macros using the "Execute Macro" action and for testing I need some of those other macros to not run, so I disabled them (using the big 'X' in the macro definition).
The problem is, they still run anyway when executed.
Is this a bug or something my patchy understanding is missing?
It looks like a bug to me, but we'll need @peternlewis to confirm.
Peter, I've also noticed (in the past) that if the sub-macro is in a Macro Group that is disabled, it will execute anyway when called from a Execute Macro Action.
Yes, the Execute Macro action can execute a macro even if it is inactive, disabled or in a disabled macro group.
Whether this is a bug or a feature depends on your point of view - enabling is about being able to trigger the macro, but you are explicitly executing the macro, it does not even need a trigger.
The Execute Macro action could fail if the macro was disabled (or inactive), but it does not currently work that way - currently it assumes you know what you are doing and executes it anyway. I would not recommend relying on this, but I also don't know if it will change.
If you want to disable the macro execution, you will need to disable the action instead.
I think it’s rash to ever assume I know what I’m doing!! So, rather than disabling the action - which would be tedious and error-prone as it appears in several places - i’ll just build a test in the macro itself to skip execution when desired.
Another option would be to create an interim macro that just executes the submacro. Then your macros execute the interim macro. Then you can disable that one action and it would disable all the others.
But you can also just add a Cancel Just This Macro action at the start of the macro and it will just do nothing and then return and continue the calling macro.
I think that is a great idea, and probably the best solution.
@peternlewis, is there any way, by KM token or script, to get the activation status of a running macro?
If there is, or you could add this, it would make it very easy to add a test at the top of every sub-macro that you do NOT want to execute if it is not (active or enabled):
Let's say you add a token "MacroIsActivated", which returns a "YES" or "NO".
Then we could do this:
This would have no impact on existing Macro, but allow us to easily prevent a non-active Macro from running.
There is a degree to which this question simply does not make sense.
When Keyboard Maestro runs a macro, it takes a copy of the actions and sets off executing them. So after it is running, the concept of “activation status” (which really applies to triggers, not actions) is meaningless.
There is a Macro condition that determines the enabled or activated state of a macro.
Well, the issue is that the macro has, in effect, been "triggered" by the Execute Macro. How is this different from the actual trigger "by AppleScript"? Why shouldn't they behave according to the same rules?
IAC, in the context of this thread, it makes perfect sense, perhaps more so if testing the "enabled" status, like this:
It doesn't make any difference how it is triggered, my comment was just that the question as asked, namely “to get the activation status of a running macro” does not make sense. You can get the activation status of a macro, as shown. You cannot get the activation status of a “running macro” because there is no concept of activation status once a macro is running.
And yes, it is somewhat inconsistent that you can trigger a macro with Execute a Macro while it is disabled or inactive, but you cannot trigger a macro via AppleScript while it is disabled or inactive.
It is plausible that I will allow triggering a disabled/inactive from AppleScript, if you specify the macro by UID (so that the macro is clear and explicit). Or alternatively (probably less likely) it is possible that I will make Execute a Macro fail if the macro is inactive. Or it is quite possible I wont change any of these behaviours. I would not recommend relying on any of them one way or the other.
Since there are several solutions that would prevent a disabled Sub-Macro from running when called by an Execute Macro, I for one would be very surprised if you made a change to KM that broke every macro that currently will run a disabled sub-macro. You have been very consistent and conservative for many years now. Thanks.
In fact using my above example provides a great deal of flexibility while achieving the desired goal. I can imagine a macro whereby the Sub-Macro is enabled or disabled, and then later the Sub-Macro is called, with its actual execution depending on the prior enablement.
I agree, I don't like breaking changes. On the other hand, it is an almost inviolable rule of Keyboard Maestro that a macro can only run if it is active. And this ability of Execute Macro to violate that rule does not fit with that.
So, as I said, I would recommend that if you intend to execute a macro by any means you ensure that macro is active (ie, the the macro is enabled, that the macro group is enabled, and that the macro group is active). Anything else is unsupported and may break in the future.
Interesting, this sounds like another workaround to just call the macro rather than with the trigger a subroutine macro to call it via it's AppleScript identity.
Good to know, I could certainly see several things breaking with the change of your mind. I'll try to use the if Macro group is active then.
I think if you were to change that it would be welcome and a bit more intutitive behavior and also make things consistent with the calling it via AppleScript and not working. It is kind of cool that it can still call on things that are inactive so I can see both arguments. If it broke people's macros then they would just need a dialog that pops up saying the macro called on is inactive please add the activate macro group or action command first. That hopefully would point people in the right direction but I can see why you would be hessitant to add that feature.
Thanks for this thread and just what I needed to know. I have ran into this a few times now.
Question: Is the best way to toggle disable a group within a macro to save a persistant variable so several macros will not run part of a macro? See the two macros following for an example of what I did. Seems similar to what Michael was after without having it be in a group. The disadvantage is you don't see that the group is disabled in Keyboard Maestro and it is just a background hidden state that is called upon.
Pro Tools - Grid - Toggle Nudge Value Change Macro (v11.0.3)