After something is copied to clipboard (using ctrl+c) I want a script (bash, python or any other language) to automatically detect that new entry is added to clipboard, change it's content and put it back to clipboard so when I paste it I get the modified text. The script should constantly run in background and monitor the clipboard for changes.
The following script describes the modification that is needed :
Source : https://superuser.com/questions/796292/is-there-an-efficient-way-to-copy-text-from-a-pdf-without-the-line-breaks
#!/bin/bash
# title: copy_without_linebreaks
# author: Glutanimate (github.com/glutanimate)
# license: MIT license
# Parses currently selected text and removes
# newlines that aren't preceded by a full stop
SelectedText="$(xsel)"
ModifiedText="$(echo "$SelectedText" | \
sed 's/\.$/.|/g' | sed 's/^\s*$/|/g' | tr '\n' ' ' | tr '|' '\n')"
# - first sed command: replace end-of-line full stops with '|' delimiter and keep original periods.
# - second sed command: replace empty lines with same delimiter (e.g.
# to separate text headings from text)
# - subsequent tr commands: remove existing newlines; replace delimiter with
# newlines
# This is less than elegant but it works.
echo "$ModifiedText" | xsel -bi
I do not want to use shortcut key binding to run the script.
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.
Dependencies
sudo apt install xsel
To compile clipnotify yourself
To USE
chmod +x "copy_without_linebreaks.sh"
.\copy_without_linebreaks.sh