I already removed any timeout options, failures, etc, but after a while, the macro just stops on its own without me cancelling it.
Any idea why that happens?
Yes. Your macro is recursive. Stop the recursion. Place the code into a loop instead of calling the macro recursively. Recursion is limited to 50 macros deep.
Yes, because there is no recursion. That is a loop. There are several options for loops. I prefer "Execute Until."
There's a limit on how many KM macros can run concurrently. The default is 50 but, "for reasons", sub-macros count double so you were probably hitting problems on the 20th "loop".
You have the problem here because you are executing the sub "Synchronously" (or rather, didn't tick the "Asynchronous" option). So the first macro can't complete until its sub-macro does. But the sub can't complete until its sub does... And so on until everything falls apart.
At least you gave alternatives -- I completely forgot!
@alltiagocom -- you can use "Retry" for this, but it isn't conceptually what "Retry" is for. "Retry" is "go back to the beginning of the loop, undoing any changes made in KM, and try again". The actions you are performing are outside KM so the bolded bit doesn't matter, but if you use it instead of a loop you might accidentally do something like (infinite loop macro, so be ready with "Cancel All Macros"):
As @Airy said above -- if you want a loop, use a loop. My preference would be to use a global flag to stop the macro "cleanly" (rather than your cancellation):
...where your "stopper" macro simply sets Global_stopFlag to "y". But you could also get clever within the macro, treating the hotkey as a toggle where if you triggered it when the macro was already running it would set the global and stop everything:
For this particular case there's no "until" scenario, that's why I just created the normal Group and yesterday I was able to work without interruptions.
So what you mean is that the first time I run the macro, it's a "normal" macro and once it runs the second time, the second one is seen as a sub-macro?
If so, I didn't know that. Interesting...
But now everything is fixed since I changed it to a group. No more stops.
I'm a bit confused about the "flag" thing. Can you clarify?
When would the flag variable change to "y"?
I was thinking that what you were suggesting would be something like:
The first time I hit Option+M it would start the macro and the second time it would stop it, but I can't see anything in your macro that suggests that?
For this particular case, I'm using this to edit audio in Logic Pro so I need an infinite loop until I hit another shortcut CMD+Option+M. That's why I set the macro and sub macro the way it is now.
Not quite. When you run it with the hot key trigger it's a macro. When the execution of that gets to the "Execute Macro 'Continuous Marquee...'" it fires up another instance of itself "inside" the original -- a sub-macro.
Because it is executing "itself" synchronously (rather than asynchronously, or another macro altogether) it's now "recursive". So you get an instance inside an instance inside an instance... None of which can complete their execution until the sub-macro they called completes its execution.
In the "v2" macro you'd use another macro/script to set the global -- just like you are doing the "Cancel" at the moment.
In the "v3" version the macro toggles itself. If it isn't running then the stop flag will be "y" so it sets it to "n" and starts looping until the flag changes again. When you next trigger the macro the flag will be "n" so it sets it to "y" and exits -- the already-running instance then sees the global is set to "y" and exits as well.
Note that Keyboard Maestro would be notifying you of the fact that the macros were canceled, but it seems very common for folks to have notifications turned off now (probably the system is defaulting or encouraging not enabling notifications?). Ensure notifications from Keyboard Maestro and the Keyboard Maestro Engine are enabled.
Yes do I have notifications turned on. For this particular macro I turned them all off, as well as the failure, because I wasn't sure if that was causing the initial issue when the macro was stopping automatically. But now that I understand that there's a limit of of macros that can be running and I changed the macro itself, I can turn those on again.
That creates an infinite loop without recursion (because "0" is always false.) I use this sort of thing all the time, and you can too. There are several ways to create infinite loops, but I find that "Execute Until" is the best way.