We’ve already shown you how to customize shortcut keys in any Linux application, but for today’s lesson we’ll take it a step beyond—and assign a shortcut key that switches an open application to be the currently focused window.

The idea is that instead of using the mouse or flipping through a set of windows in the Alt+Tab switcher, you can quickly assign a hotkey to your most important windows and switch to them with a single keystroke, saving yourself a lot of time. To accomplish this task on Linux, we’ll use the excellent AutoKey utility.

Note: if you want the Windows way to do this, you can accomplish the task with AutoHotkey easily.

The Scenario

Since I do most of my work in Google Chrome, I need to have it accessible as quickly as possible and I generally assign the Alt+G key combination to switch to my open Chrome window.

Installing AutoKey

You’ll want to open up the Synaptic Package Manager and do a quick search for autokey, check the box, and then install the package. You could also install it using the apt-get command like this:

sudo apt-get install autokey

Assigning a Shortcut Key to an Application Window

Open up the AutoKey configuration screen from the system tray icon, and then create a New Script from the menu, and then paste in the following code:

window.activate(‘Google Chrome’)

You’ll want to use the Set button next to the Hotkey setting, and assign your preferred hotkey—mine is Alt+G, though you’ll want to make sure that you use a lowercase g while setting the hotkey—if you set it using an uppercase letter it won’t behave right.

Once you save the setting and minimize or close the AutoKey configuration screen, you can hit the Alt+G shortcut key combination anytime you want to switch to the open window.

How Does This Work?

When you hit the shortcut key that you’ve assigned, AutoKey will run the script that you’ve added—in this case, it’s a simple Python script that uses the wmctrl functions to control open windows. Here’s the syntax for the window.activate function, which switches the specified window to be the active window:

window.activate(‘partial window title here’)

Basically all you need to do is match part of the window title, and in the case of Google Chrome, the window title always has “- Google Chrome” at the end.

Profile Photo for Lowell Heddings Lowell Heddings
Lowell is the founder and CEO of How-To Geek. He’s been running the show since creating the site back in 2006. Over the last decade, Lowell has personally written more than 1000 articles which have been viewed by over 250 million people. Prior to starting How-To Geek, Lowell spent 15 years working in IT doing consulting, cybersecurity, database management, and programming work.
Read Full Bio »