< Return to main page

Raising windows in stead of opening new ones

This is a pretty useful utility script for EWMH-compliant window managers, such as openbox. Since I use my terminal a lot, I don't want to get stuck with 500 terminal windows at the end of the day because of all the terminal shortcuts (W+T) I used. So, let's add a modifier to the shortcut to open new ones, and use the following script to open the first you opened.

id=$(wmctrl -lx | grep $1 | awk '{print $1}'); 
[ "$id" == "" ] && shift && $@ || wmctrl -ia $id;

With this nifty script, you can raise an existing window or spawn the program newly with the following syntax:

reraise gedit --whatever-argument-you-wish-to-pass

If you put this in your openbox rc.xml as a shortcut, you can easily assign shortcuts behaving as "only open this program anew if the window isn't there yet." Pretty useful for terminals, editors and browsers.

Simple usage example would by a local MySQL terminal: MySQL 'xfce4-terminal --title=MySQL -x mysql'

Very useful, if you, like me, hate to search for windows and prefer manhandling your array of shortcuts. Of course, you will need to install wmctrl.

< Return to main page

You're looking at a very minimalistic archived version of this website. I wish to preserve to content, but I no longer wish to maintain Wordpress, nor handle the abuse that comes with that.