The steps to follow are the same as the source in Glutanimate,Siddharth, but instead of using the program used in Glutanimate,Siddharth here the program given below should be used.
Before using the program, you must specify, in the program, the destination file of the copied text. In the case below, the destination file is /home/jim-carrey/Desktop/your-file.txt
. The program is as follows:
#!/bin/bash
# name: automatic_transfer_copied_text
# author: Ghost Rider
# source: Glutanimate and Siddharth (https://askubuntu.com/questions/1167026/detect-clipboard-copy-paste-event-and-modify-clipboard-contents)
# Automatically transfers text copied by the mouse to some text file
while ./clipnotify;
do
SelectedText="$(xsel)"
CopiedText="$(xsel -b)"
if [[ $CopiedText == $SelectedText ]]; then
echo $CopiedText >> "/home/jim-carrey/Desktop/your-file.txt"
fi
done
Dependencies :
- xsel
sudo apt-get install xsel
- clipnotify (https://github.com/cdown/clipnotify)
You can use the pre-compiled clipnotify provided in the repository or compile yourself.
To compile clipnotify yourself :
sudo apt install git build-essential libx11-dev libxtst-dev
git clone https://github.com/cdown/clipnotify.git
cd clipnotify
sudo make
To USE :
- Download this repository as zip or copy and paste the script in a text editor and save it as automatic_transfer_copied_text.sh.
- Make sure that script and clipnotify (downloaded or precompiled) are in same folder.
- Open terminal in script's folder and set permission
chmod +x "automatic_transfer_copied_text.sh"
- Run by entering in terminal :
./automatic_transfer_copied_text.sh
- Ready. While the program is running, any copied text will be sent to the specified file, in the case in question,
/home/jim-carrey/Desktop/your-file.txt
.