"Retry This Loop" acting the way it's supposed to?

I thought I understood how the Retry This Loop was working a few weeks ago, but today I noticed something that seems unexpected and counterintuitive, at least from my perspective.

So I have this macro and then I have an IF THEN action. I use the Retry This Loop at the end of a set of actions and I would expect it to go to the beginning of the IF THEN action (where the green arrow is), instead it's going to the beginning of the macro (red arrow). I know this, because I added that notification right before the IF THEN on purpose so when it runs, I close the notification manually and it keeps coming back, so the loop is not the IF THEN, but the macro itself.

Shouldn't it see the IF THEN as the loop?


I just tried adding that section to another IF THEN, to "trick" KM, but no luck. Same thing happens. It always goes to the beginning of the macro


I think the answer is the same as to your other post [SOLVED] Increase variable number indefinitely not working? - #2 by Zabobon

1 Like

So if Retry This Loop always goes back to the beginning of the macro, wouldn't it make more sense to call it Retry This Macro?

Or are there any other scenarios where it wouldn't start from the beginning of the macro?

But yes, WHILE is a good solution. Already saved that to my "KM Tips" folder.

Appreciate your help!

It goes back to the beginning of the whatever loop it finds and tries the same thing again. But because it is not "repeating" and instead is "retrying" it keeps doing the same calculation of 0 + 1 over and over.

In other words, on each "retry" it ignores the previous try.

So it's going to the beginning of the macro, as in "it's going to the first action" of the macro. I would expect it to see the IF THEN as a loop. Because if it's running the "SET VARIABLE to 0" then the loop is the macro, not the IF THEN. Does it make sense?

As you can see from my second image, I put an IF THEN inside an IF THEN and it was still going to the beginning of the macro and showing me the notification after I deleted it manually.

What it is retrying is setting the Variable to 0 and adding 1 to 0.

I think I see what you mean with the "repeating" vs "retrying". I thought that when it gets to the "Retry This Loop action, the variable would be 1 already, so when I run it again (assuming it was starting from the IF THEN action) it would keep adding to the variable.

But I noticed that the While action is not always a good fit. For example here I need it to react to a condition:


So if "Edit > Delete" IS enabled, I would want it to go right before the Type Tab action where the arrow is

That is where the Until Loop can be useful. "Keep looping something Until something is true"

Have a look at the various Engroup options:


Ok so as you can see from this macro (regardless of the increase in the variable, I just recreated the old version for testing purposes), you will see that the notification TEST will keep showing, if you close it manually, so it's indeed going to the top of the macro, it's not just reading the IF THEN. So that means that it's also reading the Set variable to 0 again. It's not storing the value and increasing, which is what I would expect it to do if it was reading from the beginning of the IF THEN. Can you test it and see if the TEST notification keeps coming back? You just need to close it every time it pops up.

Set Variable to Text copy.kmmacros (22 KB)

Keyboard Maestro Export

So the UNTIL will run the whole thing and only at the end checks if the condition is true or false? For example, if there's an action that makes the Edit>Delete enabled, it would ignore that action and keep running the other actions until it reached the bottom?

I just checked the WIKI and "The Until action condition is not evaluated UNTIL the end of the Until Loop, so it will always execute all Actions in the Until block at least once".

That's awesome! Thanks for the suggestion!

1 Like

@iamdannywyatt, I am as confused as you are about "Retry This Loop" action. It should loop back to the If Then Else action, but it is looping back outside of the If Then Else action. :confused:

1 Like


I would go a step further and I would actually say that the first "loop" is the condition itself (red line). The second (parent) loop is the IF THEN (yellow line), then the "grandparent" loop is the Macro (blue line). It would go up and up. It would be good if it was this way and we could decide which loop we are playing, based on some type of "index", 0 being the condition, then 1 the IF THEN, then 2 the Macro. If we had multiple IF THEN or other kind of loops (nested), we could go up and up, like "index 12", for example. The sky is the limit, but it would create greater control over what is being used.

But those are not defined as loops. How is Keyboard Maestro to know that you want those Actions to loop when they are not Engrouped in Actions which loop them?

I think what is going on here is that there is no loop defined. If Then Else is not a loop. So what you have is your "Retry This Loop" Action looking back to find the start of a loop and it keeps looking, not finding a start of any loop until it arrives at the first Action in the Macro.


Thanks for the clear explanation. I am not confused anymore :smiley:

Ok I see what you mean now. So basically I need actions that are, by default, actions that loop the content inside them. Got ya.
I thought "loop" was a group of actions, since they are inside a "container". That's why I was suggesting the different levels as indexes.

In that case, my suggestion of an "Anchor" action would make sense so we could jump to a particular action in the macro (unless this can be done already and I'm not aware)