Copy-paste macro does not work as usual


I have Keyboard Maestro 6.4.8 with 10.9 where I use a standard cut-and-paste macro (takes text from a Fusion VM and pastes it into applications depending on user choice). It’s a standard macro that I have used with other clients all the time. It always works flawlessly.

But not for this client on her 2 Macs. The macro is unreliable and therefore useless.

  • Instead of pasting the latest text, it sometimes pastes the previous clipboard.
  • Instead of moving Word to front, it makes it disappear.

When I cut and paste by hand (Cmd-X - Cmd-V) there are no issues whatsoever.

There are no unusual apps on the Mac that I can see.
The VM settings are the same. I have some standards.
The problem only arose over time. When I left the client, there was no unusual behavior.
I am certain that the client did not mess with the settings. (She doesn’t know how.)

The only things that’s different from my usual configuration is OS X 10.9 (usually it’s 10.11 nowadays).

How would you go about debugging this error? Are there any logs I can send for analysis?
I am at a loss here.

This sounds very much like a timing issue. I'd guess that after the paste, you delete the top clipboard entry.

Assuming I'm right, you need to put a small pause of something like .3 seconds between the paste and the next action.

And assuming I've been right so far, your other issues are probably timing-related also, and you'll need some more pauses between whatever things seem to be going wrong.

Final guess: Your user's computer is slower than yours. :slight_smile:

If I have trouble with the clipboard or timing I sometimes start by setting clipboard to a know value. Ex. NULL.
Then a copy action.
And a pause until clipboards is not NULL.

Like this:

1 Like

Of course, that works for Copying, but not Pasting.

By the way, here's another method of doing that:

1 Like

Now that’s elegant. Thanks guys.

I don’t manipulate the clipboard at all. It is Just Cmd-X - Wait .5 - Cmd-V.
I’ll play around with the pause until the clipboard is changed.

I will report back as soon as I get access to the client’s computer.

@DanThomas, you don't need the CLIPBOARDSEED() test with the "Copy" action. It is built into that action.

From action:Copy [Keyboard Maestro Wiki]

The Cut and Copy actions wait until the clipboard changes before proceeding.

One other point. With the "Pause Until" it will wait a long time, and then fail if the user has not selected anything prior to the "Copy". The default Timeout of the Pause Until Action is huge: 99 Hours.

Instead of issuing Cmd-X, you could use the code I posted above, and change the “Copy” action to a “Cut” action.

But if you have a half-second pause, then this may not be your issue, because a half-second usually long enough. However, give it a shot and see.

As it is, the issue is not related to timing. I’ve tried the “NULL” solution from above, but it still does not reliably paste the clipboard content.

Mostly the macro will just fill the clipboard and paste its contents fine. But then it works 6 times, does not work once, then works again. It’s just unreliable.

Sometimes it takes 3 or 4 seconds for the clipboard to fill, sometimes it does not get filled with text at all. The process can be watched in the clipboard history switcher.

The weird thing is that as long as I do the cut-paste by hand on the keyboard, it works every single time. The issue only arises when Keyboard Maestro does the cut-paste (Cmd-X, Cmd-V). Granted, Keyboard Maestro may not cause this, because I only did the cut-paste process about 30-40 times with both Keyboard Maestro and the keyboard.

Is there a way to trigger the keypresses differently (say with a script) that adds nothing from Keyboard Maestro to the keypress (

Perhaps you missed the suggestion by @DanThomas.

Replace the CMD-X and CMD-V Type Keystroke Actions with "CUT" and "PASTE" Actions respectively. Also, if you have any CMD-C, replace with "COPY".

1 Like

Understood. These would offer an alternative if timing were an issue. But timing is not an issue.

To restate the problem:
The clipboard does sometimes not fill when Keyboard Maestro cuts text to the clipboard. The issue does not arise when doing the cutting by hand (on the keyboard).

It has no effect whether I use Cut, Cmd-X or an AppleScript that simulates Cmd-X.

takes text from a Fusion VM and pastes it into applications depending on user choice

It may depend on the particular application where the text is copied from.

For example, @jehrler recently discovered an intermittent copy/paste issue that only happens with iWork apps and only when copied via KM.

The problem only arose over time. When I left the client, there was no unusual behavior.

Maybe she has installed some background applications that are interfering somehow? (E.g. a clipboard manager, or even things that at first glance seem completely unrelated.)

Try to boot the client’s Mac in safe mode, launch KM Engine and see if the issue is still there.

What exactly happens when you use the KM Action "Cut"?

  1. Does the Action automatically cancel due to timeout?

  2. Does the Action continue, but nothing is on the Clipboard?

Try this simple Macro:

and let us know the results.

Hi Michael

The action times out in those cases where the clipboard does not fill.
When I repeat the action, the clipboard gets pasted twice.

As I said, the issue does not happen when cutting and pasting by hand.

Do you know another way to transfer selected text from one program to another?
Getting desperate here.

Thanks and regards

How are you doing this by hand? Keyboard shortcuts? If so, which?
Could you please make a short video showing:

  1. The workflow when done manually, by hand.
  2. The workflow using the test Macro I posted above.

Unfortunately, using an old version of Keyboard Maestro, and old version of macOS, Fusion VM, and who knows what inside that and then getting inconsistent results makes it extremely difficult to make any kind of suggestion as to how to improve the situation.

You can use the Type a Keystroke to type the Command-C or Command-X. Or you could use AppleScript to simulate the keystrokes. Whether that gets you any more reliable results is dubious, since all the Copy action does is type a Command-C and wait for the clipboard to change.

As for your questions:

I can't make a video right now, as I am not that often at the client's. I am not sure what it would accomplish as you would see me doing the same thing the macro does.

In the meanwhile the IT provider of the client has upgraded to Sierra and Keyboard Maestro is now on the latest version. The problem is still there.

How are you doing this by hand? Keyboard shortcuts? If so, which?

Cmd-A, Cmd-X, Cmd-Tab, Cmd-V in this sequence.

Hard to say. I can't see anything unusual. There is no clipboard monitoring app besides Keyboard Maestro AFAICS. There's a bunch of medical software that is standard with my other client's.

[quote="Peter's mail, as I wrote him directly"]
So does it work if you simulate a Command-X keystroke in Keyboard Maestro or AppleScript?[/quote]
No, according to the client AppleScript works worse. If anybody cares the apple script is

tell application "System Events" to keystroke "x" using command down"

What next

Is there any Keyboard Maestro log I can look at that would give some information on what's happening?

For now, I will create a new Keyboard Maestro file and see if that does something. I haven't tried that. Maybe the upgrading has damaged something.
I will make an inventory of running processes and see if Safe Mode works better the next time I am there.

That’s vague.

And it’s always “hard to say” – until you have isolated it.

For example, for some time I noticed an inexplicable GUI glitch in BBEdit. I tried a couple of things, without success. One day I booted in safe mode and noticed that the glitch did not happen. Well, this taught me that the responsible thing likely was some other process/application, rather than the system or the app itself.

It took me days, but this morning I solved the puzzle and it turned out, the culprit was not one of my suspects, nor one of Barebone’s suspects; it was an app that at first glance seemed completely unrelated.

It's up to you, of course.
In my experience actually watching "over the user's shoulder" (video in this case) will often provide insightful info to me that the user was not aware of.

The KM "Copy" and "Paste" actions are very robust. I use them all the time without any issues.
Most likely, there is something outside of KM, or improper use of KM, that is causing the issue you are seeing.

Good luck!

If the sequence:

tell application "System Events" to keystroke "a" using command down"


tell application "System Events" to keystroke "x" using command down"

does not do the same thing as you manually typing Command-A, Command-X then I’m afraid it is highly unlikely there is anything I can do, and there will not be anything I can log to assist with the problem, since the events will be being generated and then the target application will be misbehaving, but the misbehaving is happening on the other side of the event queue within the target application.

Thanks for all your suggestions. They give me hope that something can be done.

Well, I’ll have to keep calm and carry on: go and isolate it. Nothing else to do here. Will report back with my findings.

FWIW, I just found that the Cut command always times out, because the Mac clipboard actually only gets filled when Fusion loses focus. The Cut command was actually never active at the client’s because of some syncing issue (it basically overwrote my changes and the script with the Cmd-X - Cmd-V was still active).