LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Articles > Jeremy's Magazine Articles
User Name
Password

Notices


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 X.org, 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 http://www.vergenet.net/~conrad/software/xsel/. While some distributions don’t include xsel, installation is the usual unpack followed by ./configure&&make&&make install.

Once installed, run the command…

Code:
$ xsel < file
...to 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...

Code:
$ xsel ––secondary < file
... operates as above, but copies the information into the lesser known secondary selection. Similarly,
Code:
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...

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

Code:
$ 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 http://hoopajoo.net/projects/xautomation.html. 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):

Code:
$ 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 10:12 PM.

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