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:

reraise.sh 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.

This entry was posted in Linux & BSD and tagged , . Bookmark the permalink. Trackbacks are closed, but you can post a comment.

Post a Comment

Your email is never published nor shared.

You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>