Hi everyone. First of all thank you for this awesome software. Saved a lot of time.
Here is the question. KM does 9 loops and stops in the middle of the 10th. It always stops on the same step. I thought maybe because this step was pixel color recognition, so I added a random click before that, but now it stops on this random click.
I manually started KM from the beginning like already 20 times and can confirm it is always in the 10th loop and always on the same step.
Can you post your macro here? Without it, it's hard to even guess as to why it might be stopping. The easiest way to do that is to select the macro, then click the Share button at the top of the window, and select Keyboard Maestro Forum.
However ... is there another part of this? I don't see any sort of 10x loop in the macro you posted. Or if it's there, can you tell us where to look? I'm pretty sure I expanded every section, and I don't see any code that's supposed to repeat 10 times.
Sorry. I initially thought maybe my macro is too long and I split it on two. Here is the step 1. Copy Paste Step 1.kmmacros (6.6 KB)
It then goes to the Step 2 (attached before). Step 2 goes to the Step 1 and so on. There are a few if/then checks, so I am not worried about an infinity cycle.
I looked at both, and I saw that each macro calls the other one. That's the only "loop" in the macros. The first macro always calls the second, and the second macro will call the first one if a certain pixels are certain colours. I couldn't find any counter that counts to 10. That is potentially an infinite loop. HOWEVER Keyboard Maestro doesn't support two macros calling each other to a depth of more than 50 in total. So when your macros call each other a total of 25 times each, I think the KM Engine will abort all of your macros.
Therefore I recommend that you stop having each macro call each other, and put them into a single macro, like this:
While "1" (loop forever)
Macro1 actions, removing the final Execute since Macro2 follows
Macro2 actions
End While
Inside Macro2, where you have "If 'condition' call Macro1" replace that with "If 'NOT condition' then Cancel Just This Macro".
If you do what I recommend, then you will not have two macros calling each other, and you can prevent the KM Engine from aborting your macro for calling itself too many times.
However this being said, I'm not sure if this is the cause of your problem. All I know is that this is a potential problem.
My guess is that it's always stopping on the same step because of the fact that you have two macros calling each other, as I said above, and are hitting the Engine's limit. I would have expected it to last 25 rounds, not 10, so maybe my theory is wrong.
...and none of these instances ever complete. So it could be that you are bumping into the "maximum allowed simultaneous macros" limit, which is set to 50 by default.
Check the "Engine log" for errors -- available from the Editor's "Help" menu. You'll probably see lines like:
2024-06-04 18:23:29 More than 50 simultaneous macros - aborting everything
It isn't just "macros" that count towards this limit, nested groups and similar within a macro are also counted -- see this thread for more.
It's not a good idea to increase the limit to avoid the problem for longer! You'll need to rethink your "control flow" and come up with a better way of doing things -- perhaps a "Controller" macro that does loop, calling sub-macros that do their thing then exit and return "control" to the Controller...
But you might -- check carefully! be able to get away with setting your "Execute a macro" actions to be "asynchronous":
I'm not sure about this -- I'm not seeing anything that actually "Cancel"s your macros under certain conditions (though that may have got lost when you split them).
It looks like you are iterating through a list (of some kind) in a Safari window, processing each item in turn. Better ways to do this include (but aren't limited to):
Gather your entire list first then use a "For Each" action to work through them
Use a "While" loop with a condition, eg "while there are still things I can grab from Safari"
Use an "infinite While" loop, eg "while calculation = 1", but have a "Cancel this macro" within the loop for when you've run out of things to process
It really does depend on what you are doing and, importantly, what sits best in your head when thinking about it!
I'll bet you are still spawning new instances that never complete, rather than actually looping. You'll need to post the whole macro so we can see what's happening.
Thank you. It actually works perfectly. I need to copy data from another machine over remote desktop ... That is why it looks slightly more complicated than it supposed to be
I obviously can't tell exactly what you're doing with the macro, but generally, you should be able to make it do what you want by putting all those actions inside the repeat loop:
That's your entire macro, but inside the Repeat action. It will run 500 times in a row, and then stop. I'd recommend, though, that you first test with the value set to two or three, just to see how it works.
To try on your original, move the Repeat action to the top, then select every other action in the macro except the Repeat, and drag them into the Repeat action.
...and @griffman has shown how to repeat a fixed number of times. And there's more...
They all follow the same pattern -- a "loop" action that contains the operation(s) you want to keep doing along with a stop condition that exits the loop at the appropriate time. Choose whichever method makes sense for the logic of your macro and the way you think about things.