Fiddling with X selections from shell scripts

May 31, 2006

I know of three command-line programs that will fiddle with the X selection (and/or the cut buffers) in a way that's useful for shell scripts: xsnarf from Smarasderagd's collection of X things, xcb, and xclip.

I use xsnarf for a variety of reasons, I think partly historical (in that I had it around well before I found the others); I'm jotting down the other two here partly so that I have the information handy the next time someone asks me about this.

You may reasonably ask why this is actually interesting. Here's why:

Shell scripts are the easy way to automate things on Unix. Doing things in X Windows sessions is no exception, but there you need some extra programs as building blocks. One of the important building blocks is some way to fiddle with the X selection (or the cut buffers); having this lets you set things up so that you can do things like select a URL in a terminal window and fire it into a browser.

Yes, yes, some terminal emulators have this specific feature built in now. Some; making a shell script to do this means it works for anything that can make an X selection. Terminals. GNU Emacs. A help browser. Everything.

I would much rather set up a general facility, once, than run around repeatedly adding yet another feature to yet another program, and hoping that I wedged it into all of the ones I care about. It's a lot easier, for a start, and it scales much better.

Written on 31 May 2006.
« An shell script idiom for choosing what file to operate on
A simple way to get a disk space usage summary »

Page tools: View Source, Add Comment.
Search:
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Wed May 31 02:19:51 2006
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.