11
3
I don't imagine this is built into the system, but is it possible to do it without too much hassle?
Say I open a specific program with a hotkey, and when I press that hotkey again, the program window is brought to the front.
I want to do this on Ubuntu 9.04.
Maybe with D-Bus? Any experts?
Update: Here's what I ended up with in case it's of help to somebody:
#!/bin/bash
if [ -f "/tmp/myterm.pid" ]; then
WID=`cat /tmp/myterm.pid`
xdotool windowactivate $WID
if [ "$?" != "0" ]; then
WID=""
fi
else
WID=`xdotool search --title "UNIQUE TITLE" | head -1`
fi
if [ "$WID" == "" ]; then
/usr/bin/gnome-terminal --window-with-profile=MYPROFILE "$@"
WID=`xdotool search --title "UNIQUE TITLE" | head -1`
echo $WID > /tmp/myterm.pid
else
xdotool windowactivate $WID
fi
Surely it can be simplified, but I'm no bash
wiz. Also, for my example to work, I created a custom profile in Terminal that applies a unique title to the window so it can be found later. The possibilities are endless!
1For this simple task, jtb's method works better, because xdotools sometimes throws X errors, and wmctrl is faster. – Ivan – 2009-08-01T00:33:43.060