Keyboard Maestro Macro Stability Advice / Hints?

I was wondering if anyone could share any insights or hints or experience in improving the reliability of a macro with MacOS.

I have a macro that runs a series of edit commands and shell scripts and applescripts on hundreds of files. It runs fine in general, but it sometimes fails to close MacOS Pages or the previous window.

The macro is called from the BASH shell in a loop. It will run for a long time and then occasionally freeze up, since the function call to the macro fails to return when the macro fails to close its window or the Pages program after an iteration.

I've usually accounted for all the interaction with a busy OS by adding a lot of pauses before and after OS-intensive calls from KM. But before I use this brute force approach more and add a minute or more after every step, I thought I'd ask the forum here for some wisdom.


PS -- I'm calling the KM macro from the shell and offloading the Mac from other programs as much as practical, but I was wondering if there was a better and more dependable method of coding the loop inside of the single KM macro itself -- also with some wisdom :slight_smile:

I’m trying to think of suggestions, but it is difficult without seeing the actual macros/scripts and seeing where things might be falling down.

One thing with long-running macros is making sure that it doesn’t get called twice at the same time. Keyboard Maestro has lock features which will prevent that, but it doesn’t sound like that is your issue.

Another is, as you mentioned, adding pauses where they might be helpful.

There are also times where I have broken up very long macros into 2 or more pieces, so if it does fail, I can run only the parts of the macro that are needed, rather than repeating the whole thing.

But again, it’s hard to know what to suggest without seeing it as a whole.