Why does my macro stop after a certain number or cycles?

This is a question I’ve had for a very long time (possibly years) but never really came around to asking. Until now…

For example, if I create a macro that prompts me to repeat X number of times, I have noticed that often times it stops somewhere midway (after around 25 cycles) thus not completing the number of times I told it to repeat.

This also happened today with a different macro. The difference is that today’s macro was programmed to continue repeating itself (I’m using a variable that sets the value to “OK” right after I click the [OK] button on a prompt) If I want to cancel the macro I simply click the [Cancel] button on the prompt.

Any idea why this is happening?


Are you trying to repeat the entire macro, or a set of actions in the macro?

For us to really help, please post your macro.

See KM Wiki: How to Post/Upload Your Macro to the Forum

My macro is setup to repeat the entire macro. I have attached it.


HPIM 20e: remove "." from end of MDSS title.kmmacros (5.1 KB)

Thanks, but could you also please upload the image of your macro?
Many of us, including me, are not inclined to download a macro without first seeing the image. And often, we can spot the issue just from the image.

I have uploaded the image. Thanks

" to from of MDSS title

I am a beginner myself so this comment is from the peanut gallery, but why are you Repeating the macro by putting an Execute Macro at the end of the macro. Why would you not just wrap the preceding part of the Macro in the Repeat Action and forget the last Action which is to repeat the Macro.

It seems to me that the Macro, as presented, is inviting an infinite loop. Every time the Macro gets to the end it launches itself again (a variable number of times depending on the setting in the last Action)

To be honest, your macro seems a bit strange to me, but then I don't understand your purpose/objective. Could you please state your objective, and provide the manual steps in your workflow that you want to automate?

Then we could offer better help.

I have the same concern. This is not the best pattern for repeating a block of actions. It would be best to use a While action (KM Wiki), and be sure to include an Action that will cause the While loop to exit. Perhaps a Prompt for User Input, or testing for the value of another KM Variable that is set in another macro.

The Semaphore Lock will only affect you if you run multiple instances of this macro, which you aren’t doing, so that is pointless.

The Prompt is really just an Alert, so you would be better using an Alert which will allow you to cancel the macro.

The variable “Variable” is always set to OK, and then tested for contains OK, so the Set Variable and the If Then Else action are pointless.

The Repeat 1 Times action is pointless.

And then we get to the crux of the problem, you are repeating the whole macro by executing the macro when you come to the end. But the top level macro will continue running waiting for Repeat to finish, which will be waiting for the sub-macro to finish. Keyboard Maestro has a safety feature which will cancel all macros if you get to the point of having 50 sub-macros all executing at the same time, which is exactly what you’re going to do, and why after about 25 iterations, it stops.

So your macro should be simply:

  • Activate Chrome
  • Repeat 9999 Times
    • Alert “Continue?”
    • Type Keystroke: Enter
    • Type Keystroke: Delete
    • Type Keystroke: Enter


Is there a way to cancel the safety feature? Keyboard Maestro keeps canceling my macros after 25 iterations.

You can adjust it, but that really is not a good solution to any problem.

If you are hitting that limit, you are writing bad macros. Post your macro on another topic and ask for help and we can show you how to write your macro so that this is not an issue.