Cancel All Macros, Except "This One"

I just checked and you can't select the All Macros Smart Group, so the only thing I can think of is to separately disable each macro group. However, I see that @Zabobon is typing, so I expect to be corrected!

Using this action:
image

can't we use those "strings" you shared yesterday?
Like
a: (for all) and then use the - to exclude a particular macro?
Hope it makes sense

No, you can't do that. The best you could do is have your "kill all but some" Macro cancel "All Other Macros" and then have it start the Macros again that you want running. (But I wouldn't recommend this - especially cancelling a backup Macro that is half-way through.)

Okay, I found this:

2 Likes

No, the way this works is:

You'd set a variable at the start of a macro that you do want to cancel, like so:

This can then be referenced like this:

Unfortunately Sleepy doesn't provide any example macros...

token:ExecutingInstances [Keyboard Maestro Wiki]

The %ExecutingInstances% token returns instance UUIDs from all running macros.

So – your notes macro would need to have saved out its instance UUID for later removal from the instance list.

Ok then I guess my best option for now, since I don't want to cancel that specific macro by accident, is to have this:

image

The problem with that is that if you have a rogue test macro that is doing damage and your Backup Notes Macro is running, the rogue Macro will continue running...

I think safer to just have a "Kill All" Macro that you only fire when things are going wrong and accept that everything gets cancelled.

1 Like

I see what you mean. Yeah maybe I can have 2 macros:

  • The one I have now
  • One called PANIC that cancels all of them, no matter what, with a different shortcut

Maybe @peternlewis could consider this on a future update...?

That would allow us to keep important macros running, especially macros that take longer to complete, while killing problematic ones.

This is a MUST HAVE macro!

Mine has saved me from hosing my entire hard drive at least twice – and from various other mayhem a few times.

I wrote it many years ago after creating a macro that failed to terminate as expected and commandeered my mouse and keyboard completely. I had to force shut-down my Mac and was a less then happy camper.

You can already do this with a little work. Did you read post #11?

I would look at this situation the other way around. When the backup Macro is running, that is the time to take a break and get a coffee, not the time to be testing other Macros. So, I would make use of KM's Progress Bar to let me know that the backup Macro is running and give me an indication of how it is doing.

4 Likes

How would you cancel multiple macros using their UUIDs? Can you use one Cancel a Specific Macro action? If so, you could set a variable at the start of the backup macro like this:

Then, the cancel macro would look like this:

Cancel All Macros except DontCancel.kmmacros (20 KB)

Macro screenshot

This probably doesn't work, but maybe there's an AppleScript that will cancel each UUID in the list...?

AFAIK you can only get a macro's name or UUID from inside that macro. What should probably work though is your macro above but with the final action replaced with a "For Each", using "Lines in Local__RunningMacros" and "Cancel a Specific Instance".

That may not be doing what you want -- remember that "is active" is not the same as "is executing"!

Edit to Add
Proof of concept. A macros called "To Stay Open" that will not be cancelled, "To Be Cancelled" which will, "Launcher" to fire up one instance of "To Stay Open" and 10 of "To Be Cancelled", and "Cancel All But..." to do the dirty work.

Fire off "Launcher" and check the "Cancel" sub-menu in the KM menu bar icon menu and you'll see all the macros running. Run "Cancel All But..." and check the "Cancel" sub-menu again, and only "To Stay Open" remains running.

Cancel All But....kmmacros (3.3 KB)

Images

2 Likes

:man_facepalming:t2: of course!!

Basically, no.

You can use the ExecutingInstances token, and the Cancel a Specific Macro action, to iterate through all executing macros, and cancel macros except ones that have recorded their ExecutingInstance token somewhere, (and the current macro as well).

So the tools are there for you to write something like this, but I am unlikely to implement an action that cancels all macros except specified macros.

1 Like

That's what I thought until I reviewed the ExecutingInstances token and used a test macro to display the UUIDs of itself and two running test macros.

I have not tested this in depth with a bunch of top-level and sub-macros, but as I read the wiki ExecutingInstances should grab all running macro instances and allow you to process them.

Peter's comments above support my conclusion -- but I wouldn't trust it absolutely without more extensive testing.

1 Like

I should have been clearer -- you can't get a running macro's name or a running macro's UUID except from inside that macro. You can get the UUIDs of all currently executing instances but (AFAIK) there's no simple way to get from instance UUID to macro name/UUID to do "if this instance was created by x theny".

Which leaves us posting the "not to be cancelled" instance UUID in a global then making sure we skip that when cancelling the other %ExecutingInstances% -- see the "Cancel All But..." demo above.

Obvious flaw in the demo is that it only preserves a single instance of any macro. A more comprehensive solution would add instance UUIDs to a list when a "to be kept" macro started and remove them when it finished -- we could then process that list before running the cancellations.

1 Like

I don't have an answer on your specific question, but I did wonder if you could approach this in a different way.

It seems like you never want to cancel your "backup notes" macro. Why then not start the backup in the background by having KM start a script in the background and the immediately finish. You can then cancel all macro's again.

Or is it not feasible to backup your notes from a script?