How to Backup Your Clipboard History with KDE’s Clipboard Widget

Kde Clipboard Widget Txt Notes Featured

Modern clipboard managers have a history functionality that allows you to select past entries to re-paste them anywhere. This history, however, can keep up to a set number of entries. After a point, it starts discarding the oldest ones. To keep some clipboard entries for future reference, you would have to bring them back to the active clipboard slot, and then enter them one-by-one in some note-taking application.

The following is a nifty “hack” to backup your clipboard history to a plaintext file, in a folder of your choice.

Note: although we are using KDE desktop’s Clipboard Widget in this tutorial, you can do the same thing in any clipboard manager that supports user-added actions like, say, Clipman.

Add the widget

To use the clipboard widget, you first have to have it on your desktop. Click on KDE’s primary menu button, on the top right of the screen, and select “Add Widgets” from the menu that pops up.

Kde Clipboard Widget Txt Notes Add Widgets

KDE will show you its widget collection on a pane on the left side of the screen.

Scroll down until you find the clipboard entry, or start typing “clipboard” in the text field at the top of the pane, to filter down the list.

Kde Clipboard Widget Txt Notes Widget Pane

When you find the Clipboard widget, drag and drop it where you want it to appear on your desktop.

Add a new action

From this configuration window, move to the “Actions” tab and click on the “Add Action” button.

Kde Clipboard Widget Txt Notes Add Action

In the new “Action Properties” window that appears, leave the “Regular expression” blank, and “Automatic” enabled. Enter a short description of your action in the “Description” field.

Kde Clipboard Widget Txt Notes Action Properties

Before you add the actual command, it would probably be best to fire up a terminal and test it before fully committing to it.

Tweak the date output

The command itself will consist of two individual sub-commands/actions. We will use the current time as each note’s filename.

For that, we will assign the output of the date command to a “NOW” variable. We won’t get into the specifics of the date command. To find out more about it, enter man date or date --help in a terminal.

In our case, we wanted the filename to look like “Hours-Minutes-Seconds__Month-Day-Year.txt,” so we set up our variable as:

NOW=$(date +"%H-%M-%S__%m-%d-%Y".)

Add the notes path

The second action in our command “dumps” the selected entry in a text file, with the “NOW” variable as its filename. We use the trusted echo command for that:

echo "%s" > /home/USERNAME/Desktop/$NOW.txt

The %s bit is provided by the widget itself and maps to the selected clipboard entry. The second section specifies the path and filename of the saved note.

For easier testing, while setting up this solution, we had our clipboard notes dropped on our desktop. We recommend you to modify this path to something else, at least after your initial tests, if you don’t appreciate a desktop filled with text files from top to bottom.

Add the command

The full, final version of our command looked like this:

NOW=$(date +"%H-%M-%S__%m-%d-%Y") && echo "%s" > /home/USERNAME/Desktop/$NOW.txt

Click the “Add Command” button to create a new command, and double-click on the “new command” placeholder to edit it.

Kde Clipboard Widget Txt Notes New Command

Replace it with your own command (or copy-paste ours) and click OK to accept the changes and enable it.

Kde Clipboard Widget Txt Notes Command Description

Add a description for your command if you don’t want its entry in the clipboard widget to show up without a name.

Kde Clipboard Widget Txt Notes Actions Configuration

With a click on OK, your changes will be applied, and when coming back to the “Actions Configuration” window, you will see your creation in the “Action list.”

Check it out

To check your new action, click on the clipboard widget after having copied some text to the clipboard.

Kde Clipboard Widget Txt Notes Clipboard List

When hovering over an entry, the clipboard widget displays a small menu on its right, the first entry of which is “Invoke action.” Click on that to access your custom action.

Kde Clipboard Widget Txt Notes Invoke Action

Select your custom action from the pop-up entries that appear.

Kde Clipboard Widget Txt Notes User Action

And that was it: if everything went according to plan, and you used the desktop path for your testing as we did, you will see your first note popping up on your desktop. From now on, you will be able to backup your clipboard history using the custom action you created.

Kde Clipboard Widget Txt Notes In Files

Two closing tips: first, make sure to always include the seconds in your file name. That way, if you take notes during the same minute, they won’t have to fight for the same file name. Second, to make this extra handy, use a folder in your favorite cloud syncing service as your path, to have your clipboard notes available everywhere.

Odysseas Kourafalos
Odysseas Kourafalos

OK's real life started at around 10, when he got his first computer - a Commodore 128. Since then, he's been melting keycaps by typing 24/7, trying to spread The Word Of Tech to anyone interested enough to listen. Or, rather, read.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox