Monday, October 22, 2012

[HOW TO] Read/Write clipboard from command line

xsel is a program that allows X selection manipulation, and it can also be used to manipulate clipboard contents.

Read clipboard

Open a terminal window and run the command bellow. The -b options tells xsel to operate on the CLIPBOARD selection and the -o is used to write the selection contents to standard output.

xsel -b -o

Write clipboard

Using the -i, xsel reads from the standard input into the selection, so for instance, the output of the echo command can be piped into xsel thus set the clipboard contents. Replace CB_DATA with is a string for clipboard data.

echo CB_DATA | xsel -b -i
Example (write)
echo "Xubuntu Geek" | xsel -b -i


xsel manpage

No comments:

Post a Comment