Clipboard Notify
Motivation
I often try to copy some content, press ctrl + c and paste it somewhere else.
But more than once I somehow haven’t pressed the copy button good enough or
the copy button on a codeblock of a website is just broken or buggy and I
paste the former content of my clipboard - which can be pretty awkward if I don’t
realise it before sending.
Another example is with password managers, which clear the content of the clipboard after a few seconds - its good to be reminded when that happens.
To prevent that I thought about a small script which sends a short notification once the content of my clipboard changes.
The solution
I just wrote a short bash script which starts at login to my desktop and checks for the
content of the clipboard every second. If it differs from the content of the previous
iteration, it uses notify-send from libnotify to send a short notification.
#!/bin/bash
clip_content=""
while true; do
tmp_content=$(wl-paste)
if [ "$clip_content" != "$tmp_content" ]; then
notify-send -t 750 "Clipboard" "New content copied to clipboard"
clip_content=$tmp_content
fi
sleep 1
done
if you don’t run a wayland session, you need to replace the wl-paste command with
the x11 equivalent.
I added it to my sway-config like
exec --no-startup-id $HOME/.config/sway/scripts/clipboard-spy.sh
and thats it. I run dunst for the notifications on my laptop - but every other notification utility should just work as good.
the bad
This programm runs constantly in the background and constantly writes the content of the clipboard into a variable. I don’t think thats a security issue (if someone or something can read the memory content of that tool - i am pretty sure it can also just read the content of your clipboard directly. And the resource consumption to run that script in the background is really low.