Latest LQ Deal: Linux Power User Bundle
Go Back > Articles > Jeremy's Magazine Articles
User Name


By jeremy at 2007-07-12 19:38
The X Window System (X) is one of those items in Linux that tends to go unnoticed by many users. To wit, even as most distributions switched X implementations to, the average, non-technical Penguinista didn't even notice. The entire transition was transparent.

X is an extremely powerful system because a network transparent and extensible layer lay between your hardware and your window manager and desktop environment. This month, let's look at a couple of lesser known X utilities that you’re sure to find useful.

First, is xsel, a command–line program to get and set the contents of the X selection. xsel was written by Conrad Parke, and is available from While some distributions don’t include xsel, installation is the usual unpack followed by ./configure&&make&&make install.

Once installed, run the command…

$ xsel < file place the contents of the named file into the primary selection. Unlike manual cut-and-paste, xsel keeps all formatting, including line breaks and tabs, in the selection.

The command...

$ xsel ––secondary < file
... operates as above, but copies the information into the lesser known secondary selection. Similarly,
xsel --clipboard< file
places the content into the X clipboard, which is managed by the xclipboard program.

You can choose any of the three selections for most xsel operations. If you don't chose one, the primary selection is used by default. To output from one of the selections to a file, simply use the > (redirect standard output) operator instead. You can also pipe information to xsel in the usual manner.

Other useful xsel options are --append, which adds to the selection instead of overwriting it; --follow, which is similar to the -f option of tail; and --delete, which deletes the current selection from the active running program. You can even exchange the primary and secondary selections with --exchange. And while xsel is invaluable used as described, the possibilities get even more interesting if you have ForwardX11 enabled that X is network transparent, the possibilities get even more interesting.

Next is xwit, a public domain utility to resize, iconify, pop, and move windows. To build xwit, first obtain imake using your distribution’s package manager.

xwit can operate on a window using either the window’s name or ID. xwininfo provides an easy way to obtain such a moniker. You can then minimize the window with...

$ xwit -iconify -id 0x2600082
... or maximize it with:

$ xwit -pop -id 0x2600082
xwit comes in handy in a variety of circumstances. For example, if you're performing a long task in an xterm window, but you'd like to know when it finishes, use xwit to pop the window. Or apply xwit to ensure a certain window only gets so much of your time by combining sleep with xwit -iconify.

Finally, there's Steve Slaven’s xautomation, available from Available under the GPL, xautomation offers a way to control X from the command-line and scripts. xautomation can also do "visual scraping," a way to find buttons and other objects on the screen. The control interface allows mouse motion, clicks, button and key presses and releases, and other arbitrary X events. As with xsel, install is the usual unpack and ./configure&&make&&make install.

Once installed, xte is the main automation program, while visgrep handles the image and button detection. xautomation is an extremely flexible utility, so in depth coverage is beyond the scope of this article. Indeed, the possibilities are almost endless, so dive in and experiment.

For example, this command moves the mouse to position (100,100) and drags the mouse to (200,200):

$ xte ‘mousemove 100 100’ ‘mousedown 1’ ‘mousemove 200 200’ ‘mouseup 1’
While X is a "silent partner" in the Linux desktop, its flexibility and extensibility should not be underestimated. With these utilities, you should be able to leverage X to gain more productivity and to automate repetitive tasks.


All times are GMT -5. The time now is 01:22 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration