How to paste from past clipboard and do not write it to current clipboard?

For example, if I copy the following content one by one:
111
222
333

Then I want to press "cmd+1" to paste 333, "cmd+2" to paste 222, "cmd+3" to paste 111, and if I use "Set system clipboard to past clipboard" function, when I press "cmd+2" it shows 222, but if I press "cmd+2" again, it become 333.

What I want is "do not make the past clipboard to current clipboard", so no matter how many times I press "cmd+2" , it always past 222.

Does Keyboard Maestro support that? Or any other ways to achieve this?

Thanks a lot.

You can't control the clipboard history "stack," unless you want to do some fancy manipulation. So as soon as you paste item number two or three in the stack, that becomes item number one (because pasting is copying, which modifies the stack). And if it was item number three, it pushed two other things down a position, which you'd then have to manipulate back into place. This will soon get very messy, I think.

A better way to do this would be to read the values from the clipboard into variables, and then use those variables for your repeated pasting. But then you need a method to know when to update those variables.

Perhaps if you explain what you're trying to do (as opposed to what you want the macro to do), it will help us offer some workable solutions.

-rob.

Hi Griffman,

Here is how I want to use that:

  1. For the job reason, I often copy several different content from one window (like EXCEL) and paste them to the form of working system (like ERP/CRM).
  2. I could remember clearly what I copied and the order of them (like name -> phone number -> address), so I want to copy them by copy 3 times, and press cmd+1、cmd+2、cmd+3 to paste them to the form directly withouth opening any clipboard or pressing down button to select what I want to past. It's quite effective.
  3. There is an old software "Hamsin Clipboard" working like this, and I use that for many years, but the problem is it offen stop working until I restart it.

Thanks, that helped. I have a solution that works, though I have it set up in a group that only works for TextEdit (for testing). My solution requires two macros: One that watches for any change in the clipboard (PermaClip Watcher), and another that inserts one of the three copied items (PermaClip Paster).

app-TextEdit Macros.kmmacros (11 KB)

Screenshot of PermaClip Watcher

Screenshot of PermaClip Paster

app-TextEdit Macros.kmmacros (11 KB)

Ideally, you should put PermaClip Watcher in a macro group that's only active in Excel—because it's going to run every time you copy something. If that item isn't text, it will quit; if it is text, it basically builds the stack of three items—creating the stack if it doesn't yet exist, or popping items down one position if it does.

The PermaClip Paster is a very simple macro; it has all three of your triggers defined, and then inserts text by typing (which doesn't change the clipboard) based on which trigger you used. This macro should go in a group that's active for your target application.

This is set up for stack of three; if you want a different number of items, you'd have to modify the macro pretty extensively—more nested "if" actions in the watcher, and more "case" actions in the paster macro.

Let me know if you need more help getting this going for testing.

-rob.

3 Likes

Hi Rob,

Thanks so much.

I tired the macros your proivde, and they are good. However there seemed to be some small issues:

  1. If the text I copy is number (like 111) / english (like abc), it works. If the text is Chinese (like 春夏秋冬), it did not work though I could see that in clipboard list. I read your macro, but still do not understand what cause this problem.
  2. Your macro is using "insert by typing", and I tried to change it to "insert by pasting" to make it more like traditional clipboard. But it did not work, is it possible to achieve that?

Thanks again.

  1. Perhaps Chinese text isn't recognized by Keyboard Maestro as "text" in the Case statement I use—that's the only thing I can think of. In the Watcher macro, change the first Case statement to "If System Clipboard does not have an image." Hopefully that will work.

  2. You cannot use Paste, because when you do, that triggers a copy action, which means the Watcher macro fires, which changes the order of items on the stack. That's why I use inset by typing. Pasting from a past clipboard in Keyboard Maestro essentially copes the item then pastes it. The entire point of this macro is to stay away from the changing clipboard, because that makes it so very difficult to do what you want to do. These macros create their own little three-item stack, and it only changes when the clipboard changes ... so in order to insert without changing the clipboard, it has to insert by typing.

Perhaps you could work around the second issue by having the Watcher macro compare the "new" item in the stack with the three that are already there; if it's already in the list, then the Watcher macro would exit, leaving your stack alone.

But that would take some testing and more time, and I've already spent about as much time as I can on this one :).

-rob.

Thanks Rob, I'll try more.

Hope in the future the Keyboard Maestro software may add this "paste from past clipboard" as an option.

The system only has the system clipboard, and Paste can only paste from the system clipboard. There is no working around this it is simply how things are.

To do what you want to do, what you need to to is either:

  • Keep the clipboard history ordered (tricky)
  • Keep track of the clipboard history order (tricky)
  • Copy the clipboard entries to saved entries and paste from them (best practice).

Note that because Keyboard Maestro does not allow duplicate entries in the clipboard, if two items can have the same content then you will run in to specific problems that will need solving.

So, assuming you have your 111, 222, 333 example in the clipboard.

In the first case you would do something like:

Command-1:

  • Paste From Past Clipboard: 2
  • Set Clipboard to Past Clipboard: 2
  • Set Clipboard to Past Clipboard: 2

Command-2:

  • Paste From Past Clipboard: 1
  • Set Clipboard to Past Clipboard: 1

Command-3:

  • Paste

The second method is considerably more difficult.

The third method would be either something like:

Copy the various desired entries, then trigger a macro to "Save" them, say Command-0.

Command-0:

  • Set Named Clipboard "1" to Past Clipboard: 2
  • Set Named Clipboard "2" to Past Clipboard: 1
  • Set Named Clipboard "3" to Past Clipboard: 0

Command-3:

  • Paste From Named Clipboard "3"

Note: if the data is plain text, you can use variables instead of Named Clipboards.

You could possibly have all your Command-1/2/3 macros check how long its been since any of them were last used and execute the Command-0 sequence if it has been long enough, or execute it when you change application, or whatever to avoid having the manually press Command-0.

Alternatively, you could have Control-1 Copy to Named Clipboard "1", and Control-2 Copy to Named Clipboard "2" so you could copy the items explicitly.

But in all cases, to Paste requires the system clipboard to be used and affects the clipboard history.

Thanks for your detailed explaination. At the moment I'm still not quite familiar with named clipboard & variables. Well, I will learn more and try them.

Actually I'm not quite clear aout the "system cliboard" you mentioned, do you mean pasting action must get the content from the only clipboard the system provided and get the latest content?

If yes, I do not quite agree about that, because another software developed 20 years ago (Hamsin Clipboard, a Windows software) could past from the past clipboards. Another sample is "PasteMate" on Mac https://pst.cgt3d.cn/ , and it provide an option to move the clipboard position to beginning or not.

I mean, the system has a single, system clipboard. It is to this that any application Copy actions happens, and from this that any application Paste happens. This is unavoidable.

So to paste from anything that Keyboard Maestro knows about, it has to go into the system clipboard. And then it can be pasted into the application (via simulating Command-V). And for complex reasons, the clipboard cannot be safely restored, so Keyboard Maestro does not restore the clipboard to a previous value.

It cannot be done reliably in all cases. So Keyboard Maestro does not do it. PasteMate can likely get away with it because after you do that specific action manually, nothing further will happen until you do some other action manually (thus, time passes, lots of time as far as the computer is concerned). Keyboard Maestro on the other hand, after you execute the action, the very next action will happen a fraction of a second later, quite possibly before the target application has done anything with the paste.

Thanks, got it. I did not consider the risks with getting past clipboards.

I will study more to see whether I want could be achieved, and I also see whether I could get familar with the new ranking rules.

My macro uses Peter's described approach #3, though with variables not named clipboards. It's really the best way to accomplish what you want to accomplish. (Note that I'm not saying my macro is the best way to do that, just that the method is the best way to do it.)

-rob.

1 Like

It might be worth emphasising again (if not for OP, then for, I am pretty sure, at least one reader out there!) that the MacOS “clipboard” contains one item. The name “clipboard” brings to mind an image of a real-world clipboard with various documents in it, so we have to imagine instead a clipboard with just one document in it!

KM offers a clipboard history—which means that items that were in the clipboard can still be retrieved.

The same is true of other applications that offer their own clipboard history—they are each keeping their own history of the MacOS clipboard.

Yes, I also use the third approach to past from the last clipboard, and it works without variable settings.

Frankly speaking, "paste from past clipboard without re-write the latest clipboard" is necessary if security risks could be solve by adding limitations or other ways, because "paste from past clipboard" is not relative to the latest clipboard by routine understanding。

I'm sorry but the wording there has lost me rather. But... I'm sure there's an answer! :wink: .

Its not a question of security, there are simply technical limitations that make this impossible, as I've described above:

  • There is only one system clipboard and anything pasted into an application has to go through that
  • The clipboard cannot be restored to its previous value immediately or the wrong thing might be pasted.

Oh, if only it was actually that simple.

Firstly, the clipboard is almost always a single thing, but usually in a whole variety of formats. So a single copied thing might include variants like: plain text; styled text; png image; tiff image; html; some proprietary format.

But, the clipboard can, but almost never does, contain multiple items. The only thing that actually does this is the Finder, when you select multiple files and copy them. And its so rare that Keyboard Maestro does not actually support this.

I thought this was talking about "security risk“ and since you also mentioned "safely" and "reliably" too. So maybe I misunderstood that.

I'm still confused. Why not to create more clipboards, like PasteMate and many other clipboard enhancing software does, instead of using the only one system original clipboard?

If worrying about many actions could be done by KM actions, maybe adding enough limitations could solve this, for example "do not allow any further actions based on pasing the past clipboard".

If too many formats of text / pic / files make it difficult, maybe just allow user to past plain text from past clipboards, since it's easy to remember several texts ( name / phone number / address / email address, etc), but for pictures and files, it's too difficult to remember.

There is only one system clipboard. And it is from this that applications Paste from.

I have no idea what PasteMate does, but the above is simple fact. There are no other system clipboards, applications cannot paste from anywhere except the system clipboard.