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

Misc

xdotool

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"
    Print

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

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

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: https://github.com/mkropat/jumpapp Doesn't work well with systray apps but my goal is to banish those.. map them to W-F1 etc.

JumpApp

https://github.com/mkropat/jumpapp → A faster way to launch applications and switch between them

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

Thanks to {Yuri Khan, Vadim Atlygin, Evan Cofsky, Tom Novelli } for help.

Mac and Microsoft Windows

How to Set Key to Switch to Browser

Linux Keybinding

  1. Keyboard Software Guide
  2. Swap Control Alt Keys
  3. Set F2 F3 F4 to Cut Copy Paste
  4. Swap CapsLock Escape Keys
  5. Make CapsLock Do Home Key
  6. Setup Shift Lock Key
  7. Add Keyboard Shortcut to Switch App
  8. Set Key Repeat Rate
  9. Set System Keyboard Layout
  10. How to Switch to Dvorak Keyboard Layout
  11. Change Volume by Command
  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.