How to make "Pause Until" work consistently?

I extensively use the "Pause Until" action in my Macros. My most common use is to pause until the middle mouse button is pressed.

Up until KM11, it worked perfectly. But since KM11, it only intermittently recognizes the middle mouse button press.

There's an explanation of why it doesn't work anymore in this thread. That thread also gives a solution of how to fix it.

Because I use "Pause Until" functionality a lot, I created the solution described in the thread as a standalone Macro. That way I can just drop it in as a replacement for the "Pause Until" action.

Yet, despite following the instructions in this thread, my macro doesn't always detect the middle mouse click. It will typically do it the first several times a Macro is run. But then after that, it will just stop working.

Attached is an example of a Macro that uses the Pause until function. It is called "Paste a List Macro (v11.0.2)". This Macro will copy the currently selected lines to the clipboard (via the copy command) and then paste a single line from the clipboard each time the middle mouse button is pressed. The lines are pasted in sequence. So if you copy 10 lines to the clipboard, line 1 will be pasted on the first press of the middle mouse button, then line 2 on the second press, then line 3 on the third press and so-on. A notification is displayed when the copy command is performed. And then other notification is displayed after all the pasting is complete and there are no more lines to paste.

The "pause until" functionality is provided by a macro called "Pause Until Middle Mouse Button Pressed Macro (v11.0.2)". That Macro makes uses of another Macro called "Pause Until Middle Mouse Button Pressed Helper". I have attached all Macros to this post.

Could someone tell me what I am doing wrong? Thanks!

Paste a List Macro (v11.0.2)

Paste a List.kmmacros (5.6 KB)

Keyboard Maestro Export

Pause Until Middle Mouse Button Pressed Macro (v11.0.2)

Pause Until Middle Mouse Button Pressed.kmmacros (3.8 KB)

Keyboard Maestro Export

Pause Until Middle Mouse Button Pressed Helper Macro (v11.0.2)

Pause Until Middle Mouse Button Pressed Helper.kmmacros (3.4 KB)

Keyboard Maestro Export

Why the extra macro? Is there a reason for more than

  1. The macro(s) that need to pause
  2. The macro that responds to your middle button press?

In the spirit of KISS, here's a two-macro demo. I don't have a middle mouse button, so change "Un-Pauser"s trigger to suit. If it works consistently for you you should be able to build on it.

Paste one line at a time.kmmacros (3.6 KB)

Image

Un-Pauser.kmmacros (2.4 KB)

Image

I have three different approaches to solving this problem. It appears to me that your problem does not involve asynchronous processes (i.e., two different macros running at exact the same time), just synchronous processes, even if they are comprised of two macros. Let's take a simple case of that situation, which simply reads the numbers aloud from 1 to 5...

Now let's say you want to use a user's action to "pause" the reading of the numbers. What I would sometimes do to let the user "pause" between each number is this:

What this will do is wait until the user moves the mouse to the upper left corner of the screen AND then moves the mouse off (the second step can be omitted if you want the user to be able to leave the mouse in the corner of the screen to disable all pauses, which is extremely useful in some situations.) Since I'm a lazy person, I find moving the mouse to "trigger" actions like this to be much more comfortable on my hands than pressing a button.

Here's an even cooler/simpler way to achieve similar results, but this method allows the users to press a modifier key on the keyboard (rather than the mouse) to perform the "pause."

This is an amazing action which waits for a change to any of the modifier keys. It has several other options in place of "modifier keys" but I suspect this one would be the most popular.

When it comes to the other case of pausing a macro that is running asynchronously from another macro, one needs an approach that synchronizes the two running macros. Using variables is the most common method, similar to the code by @big_smile. Personally, I have a Stream Deck app on my iPad and my code to perform a pause looks like this:

Notice in the above that the loop will read the numbers aloud from 1 to 30, except when the colour of the Stream Deck button that's labelled "Running" is not Green, in which case it retries the loop at the same numerical value. This creates a "pause." Naturally, I have another macro which changes the dictionary value (and the colour of the Stream Deck button) to "Red" when the user touches the button.

Of course, sometimes it helps to add additional code, so that when the macro is "pausing", the macro speaks a message something like, "Press a modifier key to continue." When I do this, I put it in a loop, so that the message is repeated, but I like to put a ten second pause between the spoken messages. The cool part of this is that my macro is written so that the pause will end immediately upon the keypress. In other words, if you press a modifier half-way during the message "Press a modifier to continue this macro," it will start your macro immediately, even before the message has finished being spoken.

Why the extra macro? Is there a reason for more than

Thanks for taking the time to reply! The reason for the extra macro is because I use Pause Until in many Macros (and not just the "Paste a List Macro (v11.0.2)" that I have posted). So I'd prefer just to have one action that calls the "pause until" functionality, rather than adding 3 steps to replace it. Plus if I include that functionality through executing a macro, and KM ever changes how it handles this again in the future, then I can just make the changes to one external macro. And then all the Macros that contain the external macro will update, rather than me having to go through each Macro to update them.

If putting those steps into each Macro is the only way to do it, I will settle for that. But I am hoping someone can tell me how to fix my external macros.

Thanks for the suggestion. In my use case, it would have to be pressing a button. Thanks anyway.

I'm sure it isn't the only way! If you do want to split it out then try again with the way you were doing it, but move the "Disable Macro..." step from second macro to the end of your third -- the quicker you disable the third macro after it's set the global, the better (yes, a macro can disable itself).

Next time things go wrong check the KM Engine log for clues -- you'll be able to see if something isn't being triggered, for example.