Views:
29,828β
Votes: 4β
Tags:
scripts
python
clipboard
Link:
π See Original Answer on Ask Ubuntu β§ π
URL:
https://askubuntu.com/q/1144385
Title:
Why is this python script running in background consuming 100 % CPU?
ID:
/2019/05/18/Why-is-this-python-script-running-in-background-consuming-100-_-CPU_
Created:
May 18, 2019
Upload:
September 15, 2024
Layout: post
TOC:
false
Navigation: false
Copy to clipboard: false
I was intrigued by this project so wrote a bash script for those more comfortable in that environment:
#!/bin/bash
xclip -o -sel clip > /tmp/LastClip
while true ; do
xclip -o -sel clip > /tmp/NewClip
diff -q /tmp/LastClip /tmp/NewClip > /tmp/DiffClip
if [[ -s /tmp/DiffClip ]] ; then
cat /tmp/NewClip # For testing dump to screen instead of printing
cp -a /tmp/NewClip /tmp/LastClip
fi
sleep 1.0
done
It does require Xorgβs xclip
package:
sudo apt install xclip
Itβs dumping clipboard contents to screen using cat
command. If you want hard copy instead replace cat
with lp
and specify your printer name, orientation and possibly βfit to pageβ option.
You will see a bit of lag to screen because I choose sleep 1.0
which would be unnoticeable with a printer and still faster than people can highlight text and use Ctrl+C.
If you copy the exact same highlighted text to the clipboard it doesnβt trigger a difference. One letter more or less will trigger a response.