In Unity, pressing Super + 1 to 9 launches or switches focus to an application. Can I assign a keyboard shortcut with a similar property in Lubuntu (i.e. in LXDE)?
More precisely, can I set up a shortcut such that if the application is already opened then focus will switch to it and the workspace will change accordingly (like in Unity)? So far I have only managed to assign a shortcut that launches (a new instance of) the application.
Best Answer
Openbox (LXDE's window manager) doesn't have an inbuilt functionality for this, but with a little help from xdotool we can write a script that can replicate and even enhance Unity's behaviour.
First, make sure you have xdotool installed:
Save the following script as
focus_or_launch
and make it executable:Here's how the script works: When you run
focus_or_launch application
xdotool will look for existing instances of the application and focus one of them. If no instance is found the script will launch a new one.To integrate this script with your desktop session edit your openbox configuration file (e.g.
~/.config/openbox/lxde-rc.xml
,../lubuntu-rc.xml
or../rc.xml
) and add a section similar to the following for each application you want to control:Make sure to replace
focus_or_launch
with the path to the script on your system or, alternatively, copy the script to your$PATH
.If you don't want the script to launch a new app instance, simply remove the following section:
P.S.: This script should work on all xdotool-compatible desktop environments (e.g. Unity, GNOME, XFCE...)