command-line tool to access X clipboard and selection buffers
XSel is a command-line program for getting and setting the contents of the X selection. It can also append and have it follow a growing file (similar to tail -f).
apt-get install xsel
#! /bin/bash firstxserver=$1 secondxserver=$2 #set the variables to the default echo . | xsel --display $firstxserver -b -i echo . | xsel --display $secondxserver -b -i clipboard=. while [ 1 ] do #get the values of the clipboard firstdislpayclipboard=$(xsel --display $firstxserver -b -o) seconddislpayclipboard=$(xsel --display $secondxserver -b -o) #if the first x servers clipboad chages if [ "$firstdislpayclipboard" != "$clipboard" ] then #if it doesnt change to be blank if [ $(echo $firstdislpayclipboard | grep ^$ -c) -ne 1 ] then #set the appropriate variables to be the contents of the first comand seconddislpayclipboard=$firstdislpayclipboard clipboard=$firstdislpayclipboard xsel --display $firstxserver -b -o | xsel --display $secondxserver -b -i else #if it is blank set it to be .in case if its because the x server went down echo . | xsel --display $firstxserver -b -i fi fi #if the second x servers clipboad chages if [ "$seconddislpayclipboard" != "$clipboard" ] then #if it doesnt change to be blank if [ $(echo $seconddislpayclipboard | grep ^$ -c) -ne 1 ] then #set the appropriate variables to be the contents of the first comand firstdislpayclipboard=$seconddislpayclipboard clipboard=$seconddislpayclipboard xsel --display $secondxserver -b -o | xsel --display $firstxserver -b -i else #if it is blank set it to be .in case if its because the x server went down echo . | xsel --display $secondxserver -b -i fi fi sleep 1 done
Пример вызова:
#! /bin/bash /bin/sh -c "X :4 -query xserver2" (sleep 5s; xsel_clipboard.sh :0 :4) & exit