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.

#!/bin/bash
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.

No Comments

Leave a Reply

Your email is never shared.Required fields are marked *