Linux: Add Keyboard Shortcut to Switch App

By Xah Lee. Date: . Last updated: .

Suppose you want to have F8 switch to browser. Here's how.

First, install wmctrl.

wmctrl is a command line util to {switch, close, move, resize, set title, list, …} windows.

# install wmctrl
sudo apt-get install wmctrl

Example use:

Type xprop in terminal to find the name of a app's window class name. [see Linux: Commands Related to GUI Apps])

here's some popular app's window class name:

Now, create a keyboard shortcut to the command.

In your Linux desktop {Gnome, KDE, Ubuntu, Xfce, …}, there's usually a keyboard setting tool in the control panel to set a key to execute command. Use that.

Here's a example from xfce:

xfce keyboard setting panel 2015-03-15
Xfce keyboard setting panel

LXDE / OpenBox

For LXDE or OpenBox, you need to modify a config file. See: Linux: LXDE/Openbox, Change Keyboard Shortcuts



Here's another method.

Here's what you can do with xdotool to switch/launch app.

This is what I came up with to switch between my editor/browser/terminal using surplus numpad keys. (Tried wmctrl -xa first but it switches to the first terminal on the first desktop it finds.)

"xdotool search --onlyvisible --class  Geany   windowraise windowfocus"

"xdotool search --onlyvisible --class  Firefox   windowraise windowfocus"

"xdotool search --onlyvisible --class  Sakura   windowraise windowfocus"

That's in 〔~/.xbindkeysrc〕 … I started using xbindkeys so I can switch WMs without redoing all my hotkeys.

P.S. - found a switch-or-launch script for Linux: Doesn't work well with systray apps but my goal is to banish those.. map them to W-F1 etc.

JumpApp → A faster way to launch applications and switch between them

The idea is simple — bind a key for any given application that will:

2012-09-15 Thanks to {Yuri Khan, Vadim Atlygin, Evan Cofsky} for help.

2014-11-30 Thanks to Tom Novelli for help.

Mac and Microsoft Windows

How to Set Key to Switch to Browser

Linux Keybinding How-to

  1. Keyboard Software Guide
  2. Swap Control Alt Keys
  3. Set F2 F3 F4 to Cut Copy Paste
  4. CapsLock → Escape
  5. CapsLock → Home
  6. Shift Lock
  7. Key to Switch App
  8. Key Repeat Rate
  9. System Keyboard Layout
  10. Switch Keyboard Layout
  11. Change Volume
  12. xmodmap
  13. xbindkeys
  14. xvkbd
  15. Find Keyboard Key Scancode
  16. X11 Keyboard Key Names

If you have a question, put $5 at patreon and message me.