Comment 2 for bug 1854092

Revision history for this message
psl (slansky) wrote :

I tried to write a simple script to collect data with "copy", script waits in the loop for data in clipboad and prints that text to stdout and clears clipboard. Simple and powerful! It works well with xclip but doesn't work with xsel, like some data are not cleaned and are put to the stdout again and again. This could be a bug in xsel. Maybe that I just miss something...

```
#!/bin/bash
# print data from clipboard to stdout, again and again...

MODE="xclip"
#MODE="xsel" # doesn't work well, clipboard is not cleaned and the same text is printed again and again :-(

function pbcopy()
{
   if [ "$MODE" == "xclip" ]; then
     xclip -selection clip -i
   else
     xsel --clipboard --input
   fi
}

function pbpaste()
{
   if [ "$MODE" == "xclip" ]; then
     xclip -selection clip -o
   else
     xsel --clipboard --output
   fi
}

# MAIN
echo -n "" | pbcopy # clear clipboard
while :; do
   TXT="$(pbpaste)"
   if [ -n "$TXT" ]; then
      echo "$TXT"
      echo -n "" | pbcopy # clear clipboard
   else
      sleep 0.1 # sleep 100ms
   fi
done

```