Save Clipboard History in Just 30 Lines of Code
In daily work or life, copy and paste are highly used. Sometimes you suddenly need the content you copied before, and it would be convenient if you have the history for reading and searching.
A simple shell script can do that!
When the script runs in background, it reads the clipboard every 2 seconds, compare the local saved record content, append current clipboard content the end of file if it has not been saved.
Files are named with dates (can easily modified it in the followed script, see OUTPUT_FILE
) for easy storage and archiving.
Implementation
Create a clipboard.sh
script file
1 | !/bin/bash |
Give executable permissions to clipboard.sh
1 | chmod +x clipboard.sh |
Run
1 | ./clipboard.sh |
Read
You can use Shell or an editor (such as VS Code) to view the document contents saved by the script.
1 | tail -f ~/Documents/2024-09-03.txt |
Related software recommendations
There are already some very useful clipboard history plugins on the market.
Raycast
PasteNow
The pro version of PasteNow supports iCloud synchronization, which is more user-friendly for viewing history across devices.
Save Clipboard History in Just 30 Lines of Code