I found myself doing the same thing all the time and wanted to automate the task. What it was? Well, I was selecting internet addresses with the mouse in X11, opening a new tab in firefox and then pasted the uri into the newly created tab, which makes firefox load the URI. Then I was clicking something else to clear the selection buffer again, to avoid accidental pastes into my IRC client.
Doing that manually over and over again sucks, so a script had to be written. That's easy enough and I got a script going which uses either `xsel' or `xclip' to manipulate the X11 selection buffer and does stuff according to what's in that buffer - all that is configurable, obviously. One such handler would be to do "firefox -new-tab $thatURI".
Now the do-something part was quite straight-forward and easy. Surprisingly, the hard part was to clear the buffer afterwards. You'd say that "xsel -c" will do the trick, but when you can still hit the middle-mouse button to paste text back into xterm, then something is off.
Here's what's going on: X11 has multiple selection buffers: Actual selection buffers (primary and secondary), the clipboard buffer and finally (and most annoyingly) cut-buffers, of which there are eight by default.
Most applications I know use the primary selection. Some use the clipboard buffer, too, like applications in which you can select `Cut' or `Copy' from context menus and such. I've never seen anything use the secondary selection.
Cut Buffers: Obsolete. Never, ever, ever use them. Ever.
And so, I didn't think anything used that stuff anymore. But some do... Like `xterm', which is the terminal emulator of my choice. By default it puts stuff into the primary selection buffer and into the first cut-buffer. To take a look at cut-buffers, you can use the `xcb' application.
But I really don't want to fiddle with these things. I want to follow jwz's advise and just leave them be. So I told `xterm' to stop being an idiot by adding the following to my ~/.Xresources file:
!! Do NOT use cut buffers in xterm. They are evil and obsolete. *VT100*translations: #override \n\ ~Shift~Ctrl<Btn2Up>: insert-selection(PRIMARY) \n\ Shift~Ctrl<Btn2Up>: insert-selection(CLIPBOARD) \n\ <BtnUp>:select-end(PRIMARY)
That tells the terminal to select to the primary selection when selecting text with the left mouse button - and not into anything else. And it also tells it, to insert the primary selection when the middle mouse button is pressed and to insert the clipboard buffer when Shift is held along with the middle mouse button (in case I need to access it because some application feels like using it).
There. My world just got a little saner again. \o/