Killing Ctrl-Tab: Better App Switching on Linux

Backstory: I like to have dedicated keyboard shortcuts to swap to and from the apps that I use the most. For example, “hyper+s” switches me to Sublime Text, my text editor. “hyper+b” takes me directly to Brave, my web browser. And so on. I use plenty of other keyboard shortcuts to swap apps and workspaces, but it’s nice to be able to reliably swap to a certain app with a single shortcut. It helps me stay in a “flow” state when I don’t have to search out a certain window every time I need it.

I used to use BetterTouchTool for this on Mac, but I now use Pop!_OS as my daily driver, so I’ve been slowly finding Linux alternatives for all the Mac apps I used to use.

Turns out, this is super easy to do on Linux, and if you use Pop!, you probably don’t even need to install anything.

Terminal Commands #

There’s a little utility preinstalled on Pop! (and easily installable on any distro that uses apt), called wmctrl. It gives you quite a bit of control over your window management, but it specifically allows you to target single windows, which is exactly what I want. [^1] I set this up on my OS, and it works well!

First try running wmctrl in your terminal, to check if it’s installed on your OS. If not, run this:

sudo apt-get install wmctrl

Once installed, the basic command to switch to a specific app is:

wmctrl -xa brave

“brave” can be any app name. This example would swap to the Brave Browser.

If you aren’t sure what app name to use, you can use this command to find the app’s “window class name”:

xprop

Run xprop and click on the window you want to switch to. You’ll see a huge output, and near the bottom it will say something like WM_CLASS(STRING) = “your-app-name”. That class string is what you should provide to wmctrl, e.g. wmctrl -xa your-app-name.

Keyboard Shortcuts #

wmctrl gives me the functionality that I want, but I still need to add the keyboard shortcuts.

On Pop_OS, you can set up keyboard shortcuts to run arbitrary terminal commands. This works exceptionally well for our purposes.

To do this, go to the “Keyboard” section of your settings app and click “View and Customize Shortcuts”:

A screenshot of the Pop!_OS keyboard settings menu.

At the bottom of this window you can click “Custom Shortcuts”, and run a terminal command based on a keyboard shortcut. I use I special hyper key on my keyboard (it simulates pressing all modifier keys at once, shift+ctrl+alt+super), and the letter of the app I want to switch to.

A screenshot of the Pop!_OS custom shortcuts window.

And presto! I can now switch directly to Sublime Text at the press of a button. I added my top four apps in this manner, and it took less than a minute.

I’m sure there’s a way you could automate this without having to enter all of your shortcuts manually, but I was pretty pleased with how easy this was. Automation can wait for another day.

← Home

Changelog
  • Adds new article on Linux app switching