Middle click the desktop to create a new note
December 1, 2014
I still use Openbox daily, but recently decided to finally give some of the big desktop environments a serious try. The last time I really tried Gnome or KDE was before their big shifts (to 3. and 4. respectively). A friend had been speaking highly of the latest Gnome versions and claimed several features of it enhanced his workflow and productivity. Was I missing out on all these great developments by sticking with Openbox? I gave Gnome and KDE another try, using them for my usual work for a few days each. There are indeed some nice features in these newer versions, and I particularly liked some of the new aspects of KDE.
But I am now back with Openbox, because I feel so much more at home in it (having spent a few years fine tuning a desktop that suits my needs), and because I still don’t understand why I need to spend so much of my laptop’s resources on window and desktop management (resources that are not a plenty with older laptops!).
One feature of KDE I particularly liked: middle click on the desktop and the text in your primary X clipboard (the clipboard that contains the text that is merely highlighted, and that is normally pasted with a middle mouse click) is pasted into a new note on the desktop. Very handy for information you quickly want to store somewhere (for however long you want to)!
When I moved back to Openbox, I immediately decided to implement that in my Openbox desktop, using xpad. Here is how I did it.
Open your favourite text editor and create the following script:
xclip -selection p -o > $FILE ; xpad --new-from-file=$FILE
(If, for some reason, you want this to work with the text you copied with Ctrl+C use “xclip -selection c -o” instead of “xclip -selection p -o” in the above script.)
Note that this requires xclip to be installed (besides xpad, obviously). If you don’t have it installed, you can do so on Debian systems with the following command:
sudo apt-get install xclip
Save the script (I saved it as ~/.scripts/xpad-middleclick.sh), and make it executable (chmod +x ~/.scripts/xpad-middleclick.sh).
Now you have to tell Openbox to run the script whenever you middle click on the desktop. Open your rc.xml file and search for <mousebind action=”Press” button=”Middle”> in the mouse section, under <context name=”Root”>. The default is as follows:
<mousebind button="Middle" action="Press">
Change this into the following (make sure the path points to wherever you saved the above script):
<mousebind action="Press" button="Middle">
Reconfigure Openbox, and you can quickly create an xpad note of the selected text whenever you middle click on the desktop.
If you don’t want Openbox to draw window decorations for xpad, add the following to your rc.xml (in the applications section):
And here is a totally unnecessary picture of the end result:
(For those of you who prefer Tomboy: I’m not sure whether you can do this with Tomboy. Unlike xpad, Tomboy does not have a cli option to create a new note from file. Perhaps it is possible to achieve a similar result using tomboycli, but I have not tried to do so.)