Cancelling the Previous Instance of Itself

I have a macro that, if triggered, should cancel a previously running instance of itself. The following group, placed at the top of the macro, accomplishes that requirement.

Group.kmactions (2.2 KB)

Keyboard Maestro Export


Interestingly, without the check of local_Instance (is not empty), the macro cancels itself. I expected the Cancel a Specific Macro action to do nothing if the Instance is null.

@peternlewis, is this the expected behavior?

1 Like

Yep -- if the "Instance" is empty the executing instance is cancelled. Simple demo:

Cancel Demo.kmmacros (2.7 KB)

As is, the "Display Text" action isn't executed. Put something, eg 1, in the "Instance" text field and the "Display" action works fine.

2 Likes

Yes. If the string is empty or “THIS” then the current macro will be canceled.

I have added a comment about that to the wiki.

3 Likes

Hello Peter (@peternlewis):wave:

Thanks for providing this feedback..

But there s something else I want to know… What happens if the Action‘s Textfield contains any possible Variable-Token (Local-,Instance- or Global Variable) instead of being an empty String or containing “THIS” and the Value from the evaluation out of the Variable-Token from this Textfield is either an empty String or “THIS” ?!

Does this action then also Cancel the Macro Instance, or do we need our own follow-up routine to Cancel the Macro with the “Cancel Just This Macro” Option ?!

Greetings from Germany :de:

Tobias

I haven't tested every possible input, but the demo above suggests that

  • The empty string or "THIS" cancels the macro (and any caller, if appropriate, following the usual "inherited Instance UUID" rules)
  • If there's a macro with a UUID matching the parameter, that macro is cancelled
  • If there is no match -- including any text/token that resolves to a non-UUID, eg "a" -- the action silently fails and the macro continues
1 Like

a.k.a. does nothing

@Nige_S, it would be helpful to replace the above with what you subsequently stated…

Strictly, this might be even better to state…

The empty string or "THIS" (or a variable or token that resolves to “THIS”) cancels the macro (and any caller, if appropriate, following the usual "inherited Instance UUID" rules)


To me, the empty string behavior is non-intuitive, thus the wiki update by @peternlewis is imporrtant and appreciated.

It certainly has no effect, but it does something -- my guess is that it sends a "cancel thisUUID" call to the Engine, i.e. there's no "if this UUID is valid" at the action level.

I'm saying "silently fails" because there's no error in the log and the %ActionResult% is "OK" -- which might be important to those who like to do error-checking.

All guess-work, of course -- I'd never even thought about this until your post!

1 Like