Window switch (wswitch) is a utility which enables you to bind a key to a particular application on Ubuntu. When the key is pressed, one of these three things will happen based on the current state.
- If the application is not running, wswitch will start the application.
- If the application is running but its window is not in focus, wswitch will bring it to focus.
- If the application is running and its window is in focus, wswitch will iconify (minimize) it.
As a first step, install the dependencies
sudo apt-get install wmctrl xwit
The best way to do this is to make a soft link of wswitch in /usr/local/bin/
- Navigate to the directory containing wswitch on a terminal.
- Run the following:
sudo ln -s $(pwd)/wswitch /usr/local/bin/wswitch
Now let's configure wswitch for your favorite application. Let's assume that your target application is Terminator.
First you need to find the WM_CLASS
of your target application.
The following will help you do that.
- Start your target application.
- Fire up a terminal (If your target application is Terminator, you are in luck).
- Run the following:
wmctrl -l -x | awk '{print $3}'
. This will print a list ofWM_CLASS
of all the windows currently open on your desktop. - Identify the
WM_CLASS
of your target application. For Terminator, this will be terminator.Terminator.
The next step is to bind a key to wswitch.
-
Open the keyboard shortcuts settings. This is usually found in
System Settings > Keyboard > Shortcuts
. -
Add a new shortcut and give it a name (like Terminator).
-
In the command section write the following:
wswitch <WM_CLASS> <launch_command>
Here
WM_CLASS
is what you found in the previous step. Thelaunch_command
is the command which can be used to launch a new instance of the application.For example, for Terminator, the following can be used:
wswitch terminator.Terminator terminator
You can also pass arguments in the
launch_command
. For example,wswitch terminator.Terminator "terminator --layout=my-custom-layout"
-
Bind your favorite key to this shortcut.
-
Hit the key and see the magic!
Create an issue or code it up and send a pull request.