How to enable Windows Key + number in gnome to switch to a window in the taskbar or panel

10

6

In Windows 7/8 and Unity, you can use WindowsKey + 1 to switch to the first application on the taskbar/panel, WindowsKey + 2 for the second etc.

What do I need to do to enable that in gnome-desktop?

TankorSmash

Posted 2013-07-02T20:36:06.523

Reputation: 281

The behaviour is described in this article http://www.makeuseof.com/tag/save-time-20-linux-keyboard-shortcuts-gnome-kde-unity/ and it's number 2 on the list.

– holmb – 2016-10-13T07:29:16.827

2@holmb Unfortunately No2 there is only for Unity. – TankorSmash – 2016-10-13T14:58:34.453

You could try to script something i.e. with xdotool and assign it to the corresponding hotkeys. – allo – 2017-07-06T15:14:46.100

... or with a Custom Keyboard Shortcut in GNOME Settings (see answer) – Steven – 2017-07-08T20:19:05.947

I'm not sure this is possible in Gnome Shell. I think the best you can do is Alt+Tab. – Seth – 2013-07-06T20:06:52.697

Answers

5

GNOME 3 does not have this functionality built-in, as you have discovered.

As a workaround, create a keyboard shortcut for a RaiseOrRun.sh script

  1. Create /home/<username>/RaiseOrRun.sh script
  2. Run chmod +x /home/<username>/RaiseOrRun.sh to make it executable.
  3. Open GNOME Settings, Keyboard
  4. For each application "Added to Favorites":
    1. Scroll to the bottom and press the + button to add a Custom Shortcut
      • Name: Choose any name
      • Command: /home/<username>/RaiseOrRun.sh <WM_CLASS> <EXECUTABLE>
      • Example: /home/<username>/RaiseOrRun.sh chromium chromium-browser
    2. Click the Edit button and press the Shortcut Key you want (ie: Super+1)
    3. Click Add to confirm

Notes:

  1. This solution knows nothing of the GNOME 3 Dash. If you want to maintain the Super+1 for first app in Favorites, you will have to keep the shortcut key and Dash position in sync manually.

  2. Display the WM_CLASS for each open application with wmctrl -l -x

  3. See also: Alt+Tab sucks; here's a solution - Exploits of a Programmer - Vicky Chijwani (explains why "run-or-raise" is better than workspaces).


Script: RaiseOrRun.sh

#!/bin/bash

# $1 - case insensitive word in WM_CLASS
# $2 - command to start application

# wmctrl 
# -a <WIN> Activate the window <WIN> by switching to its desktop and raising it.
# -x Include WM_CLASS in the window list or interpret <WIN> as the WM_CLASS name

wmctrl -x -a "$1" || "$2"

Steven

Posted 2013-07-02T20:36:06.523

Reputation: 24 804

1I really like this solution! It's very portable! Do you know a way of extending it to switch to the last recently used instance of e.g. the terminal? Moreover in Unity you are able to use shift + windows + num to spawn a new instance of an app on the fly. – Daniel Hitzel – 2017-07-10T15:52:32.750

Creating a new instance should be easy. Create a Shortcut Key to start the application. I couldn't find a simple solution for iterating through instances of a particular application. – Steven – 2017-07-10T15:59:25.997

If you stumble across one, please add it to the post ;) anyway thanks for the help on gnome – Daniel Hitzel – 2017-07-10T16:05:25.663

This sort of feature should be baked into the DE for reasons explained in my post on AskUbuntu.

– Dan Dascalescu – 2018-12-09T03:58:41.367

Steven and @daniel, regarding being able to iterate through instances of a particular application, please see my answer over at this question. Hope that helps!

– Robert – 2020-01-09T23:52:09.290

1

Gnome doesn't have a way to do that specifically, but here are some other ways to switch applications quickly.

  1. You can use Gnome's features for switching applications. Gnome has a video and tutorial on the subject here. Some highlights include typing (if you want to switch to Firefox, you can hit "super" then type "fir" and then press enter) and using the activities overview (bump the top-left corner of the screen with your mouse, then click the window you want).

  2. You can use workspaces. Gnome does offer shortcut keys for switching to specific workspaces, but they're not set by default. You can put your windows fullscreen in different workspaces and use these shortcuts for switching between them.

    For example, you could bind Super+1 to "Switch to workspace 1" and so on. Then you could put Firefox in workspace 1, Libreoffice in workspace 2, a music player in workspace 3, and then switch between them with your shortcuts.

    You can find these keyboard shortcuts and others in Settings > Keyboard. I've set some possible shortcuts in the image below.

    Gnome keyboard settings with possible workspace shortcuts set

xordspar0

Posted 2013-07-02T20:36:06.523

Reputation: 156

This is actually what I do, one workspace one application. Ended up mapping a workspace to each of the asdzxc keys, plus shift zx. – TankorSmash – 2017-07-08T19:02:25.197

0

Use this extension, A dock for the Gnome Shell https://extensions.gnome.org/extension/307/dash-to-dock/

Honghe.Wu

Posted 2013-07-02T20:36:06.523

Reputation: 139

0

I personally use https://extensions.gnome.org/extension/413/dash-hotkeys/. It seems it does exactly what you want

groovy354

Posted 2013-07-02T20:36:06.523

Reputation: 233