Cancel all Macros except for one

Hello everybody,

As most people, I have a keyboard shortcut that cancels all running macros. I now wish to make some exceptions to this, because I have certain Macros that run in the background that I wish not to cancel. It doesn't seem to be so easy to do that though. Does anybody have an Idea how to achieve that?

Best wishes

I have an idea. But I have no idea if you will like my idea.

Any macro that you "have running" probably has a "loop" in it that keeps it running, right? Why not put an IF statement inside the loop that says "If SomeVariable is 1 then abort this macro." Just set the variable when you want those macros to abort.

I've done this sort of thing for making all my macros switch from a debug mode to a non-debug mode. Or from a "noisy mode" to a "silent mode".

Yeah, I think @Sleepy's method (or something similar) is the only one that will work, but...

IMO, you shouldn't be using Cancel All Macros unless something gets stuck in a loop. And chances are, this will happen when working on a new macro, so you might not even remember to put the variable check in there, in the first place.

And it really shouldn't happen very often at all, as long as you take reasonable precautions while writing loops. Ask yourself what conditions might cause it to get stuck in the loop, and program defensively for them.

Also, I question why you have macros running all the time in the background. It doesn't sound like a typical use case for KM, but I could be wrong.

Please don't consider this an attack on you - I'm just thinking out loud here. I'm wrong all the time, so this obviously wouldn't be the first time. :laughing:

@Sleepy I currently do it similar to your proposal. I save a variable during runtime that saves the current state of the running macro. If it is "1", canceling all macros will alert me, that I still have the macro running. This seems to be ok if my original idea won't work, but I don't think it's ideal yet.

@DanThomas No offence taken :slight_smile:
Programming loops defensively is what I do by default I'd say. Except for this one macro, I don't have macros that run continuously in the background, but this one has a timer, that I simply don't want to cancel accidentally. The macro itself is stable and not the cause for needing to cancel it, but since I pretty much use KM 24/7 it does happen from time to time that I come across a macro that I have to kill and I might not immediately notice that I also killed the timer.
But as you say, I don't think it's the usual use case and therefore this problem might be less relevant for the majority of people.

Hey Ph.Dan,

How about if users were regularly inserting into any macros' loops a call to a special "cancellation macro" that uses the %ExecutingInstanceName%% token to display a list of possible macros to cancel, and let the user decide which one to cancel?

Under normal circumstances it would pop up only once per executing macro, but I think it's possible to install a time delay in which it collects the names of all running macros since it was itself triggered, maybe during a one second time period, and then let the user pick which ones to cancel.

It sounds like you're the right Ph.D. to be writing this up.

I use an approach for repeating macros that you might not have considered. I have some macros that auto-restart because they include a periodic trigger, but they also have a semaphore action at the top that prevents them from running twice at the same time. So even if I "cancel all macros", they will just restart right away. That way they aren't affected (too much) by a "Cancel all Macros" action. I find this a pretty useful feature and I use it a lot. In fact, I think I used it in a macro that I uploaded today in the Macro Library.

1 Like

I have a somewhat simple solution. The first one probably won't work for you, but I'll suggest it anyway.
Your hotkey that cancels all macros can restart the macro you want to keep running.

I assume that won't work for you, since you probably would have thought of it already. But I would think you could code the macro so that either 1) you can gracefully shut it down before cancelling all other macros, then restart it, or 2) code the macro so that if it is killed, it can be restarted and pick up where it was when it got killed.

That's my thoughts, anyway.

I still think that having to kill all macros is something that shouldn't be needed very often. So I don't think developing a complicated solution is a good idea.

If I had to have a macro running all the time, which I still think is a questionable idea, I'd write it in such a way that it could be restarted and pick up where it left off, so when I canceled all macros, I could automatically restart it.

In that case I think I'll take up the challenge.

P.S. My macro won't be for "cancelling all macro" it will be for creating a list of running macros and letting the user pick which ones to cancel. I'm not sure if it will be useful but I think I can do it, so I will try.

1 Like

I have a big smile on my face because I've got a prototype working. I've written a macro called "Cancel Menu" and what it does is generate a list of running processes (this works only when the running macros occasionally volunteer information) and it brings up a list of running macro names that you can select/cancel.

This prototype code proves that this is possible. It doesn't yet prove that it's useful, and my current version of this macro doesn't look very impressive. Here's the menu that you see when you run it. Notice that two macro names (test macros) appear in the list. When I double click on any of the items, the macro by that name is cancelled. It's cool.

Here's the user interface:

The two names in the list above are just two macros that I have running. The names are meaningless. They could be any valid string, which are the names of your running macros.

And here's the coolest statement in my macro:

image

Notice that the above statement uses a dictionary to refer to the names of running macros, and cancels the one that the user selected from the above list. It's pretty sneaky using a dictionary to store the IDs of running macros. (The index of the dictionary is the name of the instance; the keys of the dictionary are the unique ID.)

Considering that I should probably update the interface to make it more professional, I won't upload the code yet. Also, I just noticed that since I'm using the name of the macro as the key, that means if you have two macros with the exact same name running at the same time, only one of them will be visible in the list. I'm not sure if there's any way to fix that.

Wow, I have to say, I'm quite impressed that this issue sparked so much interest in you and that you've taken this to build something :slight_smile:

Keep me in the loop when you got updates on that!

Other than that. I've changed the cancel-all-macro, to check if the timer is running and cancels it more "gently" similar to what Dan proposed.

1 Like