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

  1. xsel: sudo apt install xsel
  2. 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

  1. Download this repository as zip or copy and paste the script in a text editor and save it as copy_without_linebreaks.sh.
  2. Make sure that script and clipnotify (downloaded or precompiled) are in the same folder.
  3. Open terminal in script's folder and set permission
    chmod +x "copy_without_linebreaks.sh"
  4. Double-click the script or run by entering in terminal :
    .\copy_without_linebreaks.sh
  5. Copy text in pdf and paste it anywhere. Lines breaks will be removed.