Delete clipboard

I was reading this article, but I want to make sure this is what I got from it:

Let's say I am working on a document and I select and copy "This is my first text".
Now my current clipboard has "This is my first text" has the text that will be pasted (level 0).
If I then create an action with the Insert Text by Pasting, the most current clipboard will then be whatever text I have on that action (making it level 0), replacing the "This is my first text" (making it level 1).

Now if I use Delete Current System Clipboard, it means that I'm deleting the action's text and making "This is my first text" level 0 again, right? Basically this action always delete the level 0 inside the clipboard?

The difference between Delete Current System Clipboard and Delete Past Clipboard, is that Delete Current System Clipboard allows us to pick a specific level, correct?

Yes, that’s right.

One thing to be aware of:

If whatever Keyboard Maestro pastes is identical to what was in the Clipboard before, the Clipboard doesn’t change so, deleting Current Clipboard or Past Clipboard 0 will completely delete that Clipboard entry. In other words, in that case your Clipboard won’t be “restored” to what it was before the Keyboard Maestro paste Action. You can test this by having the Clipboard History Switcher open and seeing what happens.

This caught me out recently.

If you want to be 100% sure you are restoring the System Clipboard to what it was before the Macro run a safer option might be:

Copy System Clipboard to a Named Clipboard at the head of the Macro.

Copy that Named Clipboard to System Clipboard at the tail of the Macro.


I'm going back to older threads I didn't have time to check and reply.
Thanks for the tip!

Can you share what happened to you and how that affected you? I'm assuming it did affect in a negative way? I'm curious

The item that was in the clipboard before the Macro run, was deleted instead of being restored to being the current clipboard (for the reasons I explained above). So, instead of Delete Current Clipboard or Delete Past Clipboard 0 happily restoring the clipboard to what it was before the Macro run, I lost the item that was in the Clipboard. It happened a few times before I worked out why.


Generally, my recommendation is do not do this.

Do not try to restore the clipboard to how it was before an Insert Text by Pasting action or other actions involving the clipboard.

The reason for this is it will never be reliable in general for a number of reasons, in particular because setting the clipboard is a synchronous action as far as the system is concerned, but pasting is done via the event queue (with a ⌘V), and therefore happens in the target application at an unpredictable time later. If you delete the clipboard too early, the wrong thing will be pasted. If you delete the clipboard too late, you may delete the wrong clipboard.

See: Why is the clipboard not restored after any clipboard action?

Rather than trying to work around this, just embrace it and use the various alternatives, like the clipboard history, Paste by Name, etc.

1 Like