How to Stop Actions from "Stepping" on Each Other

I've created a compound macro for Apple Mail which enters some text, then runs another macro to insert a link (see screenshot below), then add some more text. The problem is: KM starts executing the action to add the last group of text before the embedded macro is finished, which results in it co-mingling the embedded macro text with the action text.

How can I tell the root macro to not execute another action until the prior embedded macro is finished?

Also, looking at my "CC Auth" macro, am I doing this the hard way? Is there an easier way to do this?

Thanks!


There is a misunderstanding of the problem going on here.

Keyboard Maestro actions execute in sequence and Keyboard Maestro does its best to wait for the action to complete before starting the next action. This includes executing another macro (unless you deliberately make it asynchronous).

However, the way the keyboard entry works is that events like key presses are placed in to a system wide queue maintained by the system. Applications read the queue and process the events at their own speed.

So what is happening is Keyboard Maestro is adding a whole bunch of events to the event queue and the application is getting behind processing those events. The Keyboard Maestro actions have finished (they have added the events to the event queue), but the result of the actions has not.

When Keyboard Maestro simulates a character, it does wait a short time to give the application a chance to process it (and it waits longer when it simulates a command key like Command-V for Insert text by Pasting). But even so, if there is a lot of work to be done the application can get behind.

Just add a short pause at appropriate places to slow down the actions enough that the application can keep up (ideally you would use a Pause Until an appropriate condition is met to ensure the application is up to date (Pause Until the Copy menu is or is not enabled is often useful for this, assuming the application is well behaved and updates its menus appropriately), but often with this sort of thing there is no obvious condition to test for, so a timed pause with a value that allows the macro to work reliably is needed.

That makes sense. Is there an easier way to accomplish what I’m doing? As a new KM user, it’s going to take me a bit to discover the many built-in Actions and functions available, so I welcome any information as to macros I’ve created which may be “reinventing the wheel”. Or is the macro I posted the easiest way to accomplish this task?

Thanks!

What you’ve done looks fine. I missed the part with Command-K opening a sheet - you’ll often need a pause after something like that because the focus changes, and an animation is involved. Similarly, after the Return which closes the sheet. Those would be the two places where a Pause is likely needed - there is no way for Keyboard Maestro to know that a sheet, with its animation delay, is invoked at that point.

As to whether there is a better way - none that I can think of short of the RTF hack I described here.

And while it makes sense to ask “is there another/better way to do this” as an opportunity to learn how to do more with Keyboard Maestro, generally if you have a solution, there is little point in looking for a “better” solution unless its something you do a lot. You’ve already gotten 90% of the gain, spending time to get the remaining 10% is likely to be rewarding only if you enjoy the challenge, not from an actual productivity standpoint.