Script works like Windows Clipboard Windows + V
clipboard_buffer.sh is a script that saves and manages a history of copied clipboard contents on macOS. It allows users to retain multiple clipboard entries and retrieve them as needed.
- Automatic Clipboard History: Stores multiple copied items.
- Persistent Storage: Optionally save clipboard history even after a restart.
- Command-Line Access: Retrieve, list, or clear clipboard history using terminal commands.
- Lightweight & Fast: Runs efficiently in the background.
-
Download or create the script:
curl -o ~/clipboard_buffer.sh https://your-repository-url/clipboard_buffer.shOR manually create
clipboard_buffer.shin your desired directory. -
Make the script executable:
chmod +x ~/clipboard_buffer.sh -
Move it to a system-wide accessible location (optional):
sudo mv ~/clipboard_buffer.sh /usr/local/bin/clipboard_buffer
Run the script in the background:
./clipboard_buffer.sh &Or if moved to /usr/local/bin:
clipboard_buffer &To display all saved clipboard entries:
cat ~/.clipboard_historyUse pbcopy to restore a previous clipboard entry:
tail -n 5 ~/.clipboard_history | fzf | pbcopy(Requires fzf for interactive selection)
> ~/.clipboard_historyTo keep the script running after system restart, set up a LaunchAgent:
- Create a
.plistfile:mkdir -p ~/Library/LaunchAgents nano ~/Library/LaunchAgents/com.user.clipboard_buffer.plist
- Add the following content:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>com.user.clipboard_buffer</string> <key>ProgramArguments</key> <array> <string>/usr/local/bin/clipboard_buffer</string> </array> <key>RunAtLoad</key> <true/> <key>KeepAlive</key> <true/> </dict> </plist>
- Load the LaunchAgent:
launchctl load ~/Library/LaunchAgents/com.user.clipboard_buffer.plist
To remove the script and its history:
rm -f ~/.clipboard_history ~/clipboard_buffer.shIf using LaunchAgent, unload it:
launchctl unload ~/Library/LaunchAgents/com.user.clipboard_buffer.plist
rm -f ~/Library/LaunchAgents/com.user.clipboard_buffer.plist- Script stops after sleep? Use LaunchAgent or rerun
clipboard_buffer.sh &. - Not capturing clipboard? Ensure
pbpasteandpbcopywork correctly. - Permission issues? Run
chmod +x clipboard_buffer.sh.
MIT License. Feel free to modify and distribute.
For updates and improvements, contribute at GitHub Repository.