I figured out the solution and have posted it on my blog. wmictrl did the trick. I found a script on fluxbox wiki which finds an application if its already running and raises its window or launches it if no instances is running. I'm using that script with certain tweaks to launch applications.
I have documented it here:
http://www.humbug.in/2011/single-keyboard-shortcut-to-launchraise-an-application/
I updated the script to support arguments, the result is:
#!/bin/bash
# Find_app
# Author: Lucas van Staden (lvs at dedmeet.com / http://www.dedmeet.com)
# This little script will try and find the application attempting to start
# in the running processes, and if found, focus the application
# if not found, a new instance will start
# usage:
# find_app.sh <application with full path>
# params
# 1 - application to start (full path)
# helper applications
#!/bin/bash
# Find_app
# Author: Lucas van Staden (lvs at dedmeet.com / http://www.dedmeet.com)
# This little script will try and find the application attempting to start
# in the running processes, and if found, focus the application
# if not found, a new instance will start
# usage:
# find_app.sh <application with full path>
# params
# 1 - application to start (full path)
# helper applications
DOLLARONE=$(echo $1 | sed -e 's/[\t ]*$//') #Delete trailing spaces
WMCTRL=`which wmctrl`;
GREP=`which grep`;
APPLICATION=$(echo $DOLLARONE | cut -d ' ' -f 1)
if [ "x$APPLICATION" != "x$DOLLARONE" ]; then
APPARGS=$(echo $DOLLARONE | cut -d ' ' -f 2)
fi
BASENAME=`basename $APPLICATION`;
BASENAME=`echo $BASENAME | tr "[:upper:]" "[:lower:]"`
FOUND=0;
function findwindow {
# 1 = BASENAME
# 2 = WMCTRL
# 3 = GREP
IFS=$'\n';
for RUNNING in `$2 -l -x`
do
if [ `echo $RUNNING | tr "[:upper:]" "[:lower:]" | $3 -c $DOLLARONE` -gt 0 ]
then
HOSTNAME=`hostname`
WINDOW=${RUNNING#*${HOSTNAME} }
$2 -a $WINDOW
FOUND=1;
fi;
done
}
if [ "x$APPARGS" = "x" ]; then
findwindow $BASENAME $WMCTRL $GREP;
if [ $FOUND -eq 0 ]
then
$APPLICATION &
sleep 2;
# Try and find the application, after opened
findwindow $BASENAME $WMCTRL $GREP;
if [ $FOUND -eq 0 ]
then
# Still not found, wait a bit more, and try again
sleep 3;
findwindow $BASENAME $WMCTRL $GREP;
fi
fi
else
$APPLICATION $APPARGS &
fi
Add the above script to your path, possibly in $HOME/bin/find_app.sh and make it executable and make sure its in your path.
make sure wmctrl is install
sudo apt-get install wmctrl
Now update the desktop entry files of the applications you want to have a singular shortcut for launching as well as raising, so that the applications are invoked through the above script.
For eg.
cp /usr/share/applications/firefox.desktop ~/.local/share/applications/
Edit firefox.desktop in ~/.local/share/applications/ and change Exec to
Exec=find_app.sh "firefox %u"
Now add keyboard shortcut for your default broswer System Settings => Keyboard => Shortcuts => Launchers => Launch Web Browser
Now restart gnome shell => Press Alt r to bring up the run dialog. Input r and press Enter.
Now you should be able to launch/raise your browser using a singular keyboard shortcut.
wmctrlcan do it. – Gilles May 15 '11 at 11:19