How to pause until a KM action is complete?

This has come up for me multiple times before and I usually solve it by inserting a specified pause that is long enough to ensure the action is finished before the next action starts. Otherwise, the next action(s) may not work right or at all, or the macro may be stopped.

I now have a macro that makes that approach unfeasible. Selections are copied to the clipboard, then set to a variable. Then, I search the variable using regular expressions.

The problem is that most of the selections are short (less than a page or a few pages) but some are extremely long, in the hundreds of pages. The long selections make the macro not work (the selection either isn’t copied to the clipboard or isn’t transferred to the variable). The only way to make it work is inserting a very long pause, and even then sometimes it doesn’t seem to be enough time because the process doesn’t work at some point.

The macro always works on the shorter selections so I think it must be to do with longer selections making the actions take too long to finish. Even if I could decipher exactly how long the longest ones needed, to make the macro always wait that long would increase the total time for the work an incredible amount since this needs to be repeated thousands of times at the least and most of the selections are short and quick. I also must work in a specific order so I can’t set the longer ones aside until later or anything like that, and the goal is to have the macro work (as quickly as possible) without needing input from me.

I can’t seem to figure out how to make the ‘pause until’ work to wait until a KM action is complete.

I also tried making multiple macros each with a single part of the sections that hang. Then on the first, I asynchronously executed the next macro, and then on that next macro I paused until the previous macro was inactive, and continued the same pattern through each macro. This didn’t work though. The macro is completely pausing (I left it for minutes to make sure; I think it’s at the first ‘pause until previous macro is inactive’) and I have to manually stop it, when it then tries to quickly finish the macro process as it’s stopping.

Understanding how to solve this will help me in all my macros since this sort of thing regularly comes up even if not this extreme usually.

Take a look at this macro:
[CB] How to Detect When Clipboard Has Changed [Example]

I'm well aware of your problem with the right pause @sursur The approach with the "pause until" campaign is already very good.
I always end the pause with a "key condition" (here escape). Maybe that's the answer for you.

As an alternative I also see the action "found image condition".

I actually have a simple set of actions saved as a group in KMFAM that I use whenever I have a macro where I want it to wait until the clipboard has changed before proceeding (it uses the same principles that @JMichaelTX demonstrates in the macro he linked to):

Wait for Clipboard to Change.kmactions (1.0 KB)
25 PM