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

see How to Set Key to Switch to Browser

Linux Keybinding Topic

  1. Linux: Keyboard Software Guide
  2. Linux: Swap Control Alt Keys, xmodmap
  3. Linux: Set F2 F3 F4 to Cut Copy Paste
  4. Linux: Swap CapsLock Escape Keys
  5. Linux: Make CapsLock Do Home Key
  6. Linux: Setup Shift Lock Key
  7. Linux: Add Keyboard Shortcut to Switch App
  8. Linux: Set Key Repeat Rate
  9. Linux: Set System Keyboard Layout
  10. Linux: How to Switch to Dvorak Keyboard Layout
  11. Linux: Change Volume by Command
  12. Linux: xmodmap Tutorial
  13. Linux: xbindkeys Tutorial
  14. Linux: xvkbd tutorial
  15. Linux: Find Keyboard Key Scancode
  16. Linux: X11 Keyboard Key Names

Ask me question on patreon