How to filter & edit all my System Clipboard histories

Hi all, I've searched the forum and internet but couldn't find the answer to this specific question.

What I'm trying to achieve is that I want to go through all items in the System Clipboard History (for each), filter & edit each of them, and save them back so that System Clipboard History will have the new values now. It's ok if the macro takes a bit longer to run, because it's like a house keeping job.

The motivation is this: I have "Save Clipboard History to File" turned on, and I keep a record of up to 1,000,000. I want it to behave like *nix history command which keeps a long record across days. But the problem is that when I have big chunks of text or images on the clipboard, it drags the history switcher window super slow.

I'm writing a macro triggered by cron to get rid of those big guys - I'm ok with losing images and big text from the history, as long as I get to keep the other ones.

Any help would be greatly appreciated. And kudos to Peter for the great software that saves people's time

Wow! I can't begin to imagine having a million saved clipboards. That seems totally unmanageable to me.

So, IMO, let me say this first: From what little I know of your requirements, I think you have chosen the wrong tool. The KM Clipboard History Manager is just NOT designed for that scale.

I think you need a database to store, search, and mange that much data, with perhaps keeping any large images in files with the path stored in the DB.

But to get started, you could use a file-based system. KM has a great tool for this:
Append a File Action.

Of course, this works only with text, but you could also store/append a path to other files, like images.

Then you could use the KM Search using Regular Expression action using your "nix history" file as its source.

One issue is that making any changes to the Clipboard History creates another clipboard item.
AFIK, there are no KM tools to get the properties (like size, creation date, etc) of each Clipboard in the Clipboard History Switcher . @peternlewis, please correct me if I'm wrong.

So I don't think you can write a Macro, or even an AppleScript, that will look at each Clipboard and determine if its size is > some value.

Wheras, if you store your data in a database/file, with each image in its own file, then you can easily get this information.

Sorry I can't be of more help -- I just don't see KM as a good tool for this.

1 Like

As far as I can see, everything @JMichaelTX said is spot on.

This is just not going to work - Keyboard Maestro is absolutely not designed to have a clipboard history of anything like that magnitude. Heck, if your usage is graphics heavy even the default 200 items may be pushing it.

You will need to find an entirely different approach to the problem.

Probably a Clipboard Changed triggered macro, and writing to a file would be a start, but even files is not a good solution for 1,000,000 entries.


Thanks for the very helpful replies. Append a File rings a bell

I'm now exploring towards this direction (because I don't often need an ancient Clipboard item from X days ago - but when I do, more often than not I need it desperately, e.g. lost password):

I keep clipboard history up to 2,000 now. Everyday, a cron trigger would run to dump clipboard history items from today. There's no way I could have more than 2000 items in a day, which means I won't miss an item.

New item naturally flashes out the old according to 2,000 limit. The backup job is based on timestamp, not number, so that it would work.

How do I go about implementing this daily job?

May I know the path for clipboard history please? I searched docs but no luck :frowning:

All the Keyboard Maestro files are in the ~/Library/Application Support/Keyboard Maestro folder. Mess with this at your peril, most of the files in there are not designed to be messed with.

Hi Peter, in that case how can I achieve the goal of backing up clipboard history (along with metadata, e.g. clipboard timestamp)?

I'm thinking of simply backing up this file:

-rw------- 1 wang.boyang staff 265M Jul 22 14:54 Keyboard Maestro Clipboard History.kmchunked

it's at 265M now

You can back up that file, but it's going to be ugly. It is a completely proprietary and subject to change format, and it will roll over slowly as you go through your clipboards , so you would never know when to backup the file, or what it contains.

Using Keyboard Maestro in this way to record your clipboard history will not work well.

The best you could do is to have a macro with a Clipboard Changed trigger, examine the clipboard to see if it is an image or text, and save it appropriately. Record the front application and the time.

But that wont work for non-text, non-image clipboards, won't record the entire clipboard, and may have inconsistent meta data.

Keyboard Maestro is not the tool for generating some sort of long term historical record of your clipboard history.

1 Like