Ubuntu - Is there a way to associate keyboard shortcuts to bring a window to front?

I am using exactly 3 programs: - a browser - a terminal - a code editor

I keep all in fullscreen windows.

What I need is to be able to bring any one of them up with a simple keyboard shortcut, like Ctrl+Alt+B for browser, etc.

Alt-Tab sucks because I have to stop and see where the selector is.

Using 3 workspaces is better but still not ideal - I need to think about where I am and where I need to go. E.g. My browser is on top of my terminal and my code editor is to the right of the terminal. So to move from browser to terminal I use Ctrl+Alt+Down, but to move from code editor to terminal I have to do Ctrl+Alt+Left. Instead I should just do Ctrl+Alt+T for terminal, for example.

Thanks!


I don't use Unity so this is tested on Cinnamon but the same trick should work in all desktop environments. You can use a tool like xdotool or wmctrl that allows you to script your interactions with the X server.

I prefer wmctrl, but you can install both with

sudo apt-get install xdotool wmctrl 

First run wmctrl -l to see what the names of your open windows are:

$ wmctrl -l
0x02200007 -1 oregano Desktop
0x0380007f  1 oregano Ubuntu - Is there a way to associate keyboard shortcuts to bring a window to front? - Super User - Mozilla Firefox
0x01c000a3  1 oregano emacs@oregano
0x03c00006  1 oregano Terminal

If you scroll right, you'll see that the second is my firefox instance showing this page. So, you now activate each of your three windows by name:

$ wmctrl -a terminal 
$ wmctrl -a firefox
$ wmctrl -a emacs

You can assign shortcuts to each of these commands using your desktop environment's GUI or via a more generic tool such as xbindkeys.