Concerning Named Clipboards

I have a macro which copies a selected passage to a named clipboard. I have learned through trial and error that performing this action also copies the same selected passage to the system clipboard which I would like to not be changed. Accordingly, I have had to write my macro to save a variable in order to put the system variable back to it's previous setting.

I know you will ask to see the macro, but this is a simple question: Does the macro command "Copy to Named Clipboard "namedClipboard" copy to the system clipboard in order to get to the named clipboard?.. Or is this a possible KBM programming error?

Yes, Keyboard Maestro does use the System Clipboard to do this. You can see this in action if you have Keyboard Maestro's Clipboard History Switcher visible when you run that Action.

I have found that Keyboard Maestro Actions that have "Copy" or "Paste" in their name make use of the System Clipboard and change the most recent Clipboard. That includes the Action "Insert text by Pasting". And the Action that you are using is called "Copy to Named Clipboard".

I think the main designed use of Named Clipboards is for long-term storage and retrieval of images or styled text. And as you have found, as they make use of the System Clipboard they are not a way to avoid changing the System Clipboard.

2 Likes

Thanx for that explanation. As stated, I have adjusted to circumvent this issue, but I am grateful just to understand it... Thanx again!

1 Like

You can get your system clipboard back to its original state by deleting the most recent clipboard. I’m not at my Mac, so I can’t give you the exact name of the action, but you should be able to find it once you know it exists. It’s easier to do this than to use a variable as a temporary holder.

1 Like

Wonderful... Thanx, I did find that... I'll give it a go!

@Paxapunch in case you haven't found the action @drdrang is referring to it's this one. Note that you need to set it to 0 to delete the last system clipboard entry. If you set it to 1 it will delete the penultimate entry.

Delete Past System Clipboard.kmactions (442 Bytes)

Action Screenshot (click to expand/collapse)

The wording "Delete Past Clipboard" rather than "Delete Past Clipboard Entry" always leaves me a little hesitant. @peternlewis

Just for completeness, another way to restore the System Clipboard to what it was before the Macro runs is to do this (I have found this works, whatever the clipboard has in it, i.e. image, text, styled text, even App specific data etc). And you don't have to count up how many past steps to restore.

3 Likes

A great method. I use it on some macros that I'm too lazy to keep track of clipboard changes :sweat_smile:

Hi, @drdrang. Thanks for sharing. I thought this method would only work for plain text. Is Temporary a global variable or some special option for that action?

Temporary is a named clipboard. So it’s just putting the system clipboard onto a named clipboard and then using that named clipboard to set the system clipboard at the end of the macro.

2 Likes

The reason for using a Named Clipboard rather than a Variable is that while Variables can only hold plain text, Named Clipboard can hold whatever was in the Clipboard.

1 Like

@cdthomer and @Zabobon, thanks for pointing that out. I missed that important detail; I must need more sleep. :flushed:

2 Likes

That's a great trick... Unfortunately it won't work for the macro I am working on right now because I change several clipboards and just want to set it back to an earlier condition that was set during this macro. However, I will put that in my bag of tricks for possible later use!

I also especially like know more about the difference between what the clipboards and variables can contain... Very useful to know...

Here's a follow on question concerning clipboards (and variables)... What happens if I happen to delete a clipboard (or variable) in KBM preferences and find that it happened to still be in one of my macros somewhere. Does my macro stop working? Do I get some form of notification?

It depends on whether that variable is dynamically recreated as part of that (or another) macro. If it isn't, then yes, any macro that references it will run into problems.

1 Like

If you delete a named clipboard from the preferences window that is still present in one of your macros you get a notification saying it will be recreated as shown in the screenshot. Any macros that set that clipboard will still work. Any macros that rely on that clipboard already being set may fail depending on how you have the named clipboard actions settings.

Screenshot (click to expand/collapse)

If you delete a variable from the preferences window, there is no notification. Any macros that set that variable as part of the macro will continue to work. But any macros that rely on that variable already being set may not. That's why any global variables I absolutely need to be permanent I prepend with DND__ that way I know not to mess with them if I'm going through my variables list.

2 Likes

I have an opposite concern about a Copy shortcut. I use it (and similar ones for cut, copy, paste and paste match style so I can use FKeys for those actions (instead of command x, etc.).
My macro clears the system clipboard, then executes copy.

Set System Clipboard to Text “” (plain text, text field is empty)
Copy

This mostly works, but occasionally what gets pasted is whatever was in the system clipboard previously. Redoing the select, copy macro, paste works the second time. In fact that just happened when I pasted the steps copied from Keyboard Maestro.

Is there a reason you want to clear the clipboard before copying?