Cancel a looped macro that has finished

I have a pretty simple macro with a prompt of how many times I would like to repeat it, Then it fires off some keystrokes. I have a few I've created for audio editing within Pro Tools for things like moving clips around, extending the beginning of a clip by an amount, or putting fades on it. It does the actions, moves to the next clip and repeats.

The macro fires very quickly and then it just takes the program a while to catchup to all keystrokes. During that time, I cannot cancel the macro, because the macro itself has already completed.

I'd love a way to get around this if possible. Any ideas? It would seem something would have to watch for other macros between each loop.

Currently I just limit myself to the amount of commands that would equal 64, since that's how many levels of undo I have within Pro Tools. :smile:

Here's an example:

Thanks so much!

Simulated events go in to the event queue. As you note, once Keyboard Maestro has simulated those events, its job is done - then the system and the application will work their way through the queue. This is why simulating key strokes is often the most robust way of performing a macro since the timing usually does not cause problems.

If you wish to be able to cancel the macro and have it cancel the text insertions part way through, then you need to deliberately slow the macro down to a speed that is slow enough that the event queue is not filling up, and that the system and application are processing the keys as fast or faster than they are being added.

There is no way to detect the length of the event queue, so the easiest way to do this would be to add a short pause at the end of the repeat loop.

Then you can cancel the macro and no more keys will be added to the event queue and the application will stop more or less immediately.

That is such a simple solution. I can’t believe I didn’t think of that. I was way over thinking this. Of course I could put in pauses! I’m waiting for the actions to take place anyway, so it’s not like I’d lose any time. I could slow the macro down considerably to be more in time with the system and application response. I’d just have to work out the timing so they are closer in sync and then I should be able to cancel it as it run. Thanks for taking the time to respond Peter. I’ll give it a go and let you know how it worked.

1 Like