Detect clipboard copy/paste event and modify clipboard contents
Solution 1:
Credit goes to Kenn.
I modified the script to my requirements and added the function to detect clipboard copy event and modify its contents.
Source.
Remove Line Breaks when copying text from PDF (Linux)
This bash script removes line breaks when copying text from PDF. It works for both Primary Selection and Clipboard of Linux.
#!/bin/bash
# title: copy_without_linebreaks
# author: Glutanimate (github.com/glutanimate)
# modifier: Siddharth (github.com/SidMan2001)
# license: MIT license
# Parses currently selected text and removes
# newlines
while ./clipnotify;
do
SelectedText="$(xsel)"
CopiedText="$(xsel -b)"
if [[ $SelectedText != *"file:///"* ]]; then
ModifiedTextPrimary="$(echo "$SelectedText" | tr -s '\n' ' ')"
echo -n "$ModifiedTextPrimary" | xsel -i
fi
if [[ $CopiedText != *"file:///"* ]]; then
ModifiedTextClipboard="$(echo "$CopiedText" | tr -s '\n' ' ' )"
echo -n "$ModifiedTextClipboard" | xsel -bi
fi
done
Dependencies
-
xsel:
sudo apt install xsel
-
clipnotify. You can use the pre-compiled clipnotify provided in the repository or compile yourself.
To compile clipnotify yourselfsudo 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 copy_without_linebreaks.sh.
- Make sure that script and clipnotify (downloaded or precompiled) are in the same folder.
- Open terminal in script's folder and set permission
chmod +x "copy_without_linebreaks.sh"
- Double-click the script or run by entering in terminal :
.\copy_without_linebreaks.sh
- Copy text in pdf and paste it anywhere. Lines breaks will be removed.