2

Asked on the forums, but no luck. How can I switch among windows using the Win key plus the numbers 1 through 9, like in Windows or in Ubuntu's Unity?

These keyboard shortcut have saved me tons of time over the years, and I find it surprising that such a popular desktop environment like Cinnamon doesn't implement them by default. I have my file manager always open as the first window, my terminal window as #2, IDE as #3, browser as #4.

Assigning manually Win+1/2/3/etc. is a non-starter, because it will always launch a new instance of the app. Some apps might have a "one instance only" option, but that's the exception, and even then, you'll see the flicker of the new instance being launched and then killed.

3 Answers 3

2

What you are asking is in fact possible with a simple hack. In my case, I wanted to bind Super+2 to "either switch to emacs if possible, otherwise open it". To get this working in Cinnamon, first sudo apt install wmctrl (or whatever other method to install packages on your Linux distro), then, with emacs (or whatever application you want to bind) open, do wmctrl -x -l to get a list of your current open windows: I got

0x0440013f  0 emacs.Emacs           username-debian-x1 emacs@username-debian-x1

Now take that emacs.Emacs and write the following bash script:,

#!/usr/bin/env bash
wmctrl -x -a emacs.Emacs || emacs

and put it somewhere like ~/Documents/switch-emacs.sh, then do a chmod +x on that file to enable execution, then in the Cinnamon keyboard settings, you can create a custom command and select that shell script, then bind Super+2 (or whatever you want) to it. This should work immediately (tested on Cinnamon on Debian 10 buster stable).

Source: a comment found on Github

Note the reason that we needed to put it in a shell script instead of just typing the wmctrl command directly into the custom command is because the || operator doesn't seem to work correctly when passed directly to the keyboard shortcut.

Update: It seems that as of cinnamon version 4.2.4-1 (and possibly earlier), this Super+number "open or switch to" feature is builtin to Cinnamon, and works out of the box without needing the hack above. However, as of September 2019, only rolling distros like Arch have cinnamon versions this new; with Mint, Ubuntu, and Debian, you still need to use the hack above (as of Sept 2019), until cinnamon version numbers for those roll forward enough.

1
  • 1
    In order to just type the wmctrl command directly into the custom command you can do sh -c 'wmctrl -a {win title} || {cmd}', according to here Commented Jan 31, 2023 at 22:38
2

In newer versions (supposedly at least as of Linux Mint 20 [1]) this is built directly into Cinnamon as part of its "Grouped Window List" panel applet and enabled by default.

Since it's enabled by default, it can be disabled (and enabled again) from System Settings > Applets > Grouped Window List [Configure, i.e. the little gear icon] > General > Enable Super+<number> shortcut to switch/open apps.

[1] Looks like the feature was already present when the Grouped Window List was added into Cinnamon (82d8170), before being briefly removed (94719c2), then re-added (48ac13f) after complaints, then finally made configurable (linuxmint/cinnamon#9175).

1

I use antiX-linux and made this activate_windows.sh script:

#!/bin/bash

# Script to activate windows with a specific classname
# Usage: ./activate_windows.sh classname

# to identify the classname and class of a window, run `xprop | fgrep CLASS`, and click on the desired window

windows=$(xdotool search --classname "$1") # Get the IDs of all windows with the specified classname
current=$(xdotool getactivewindow) # Get ID of current active window

# if current window is from classname, minimize
if [[ "$windows" =~ "$current" ]]; then
    xdotool windowminimize "$current"
    windows="${windows//$current/}" # removes the window from the list, so as not to open it again
    found=true # at least one window found
fi

for id in $windows; do # while there is a window to open
    # activates the window, dumps stderr to stdout (2>&1), and saves the output (stderr and stdout) to the variable $error
    error="$(xdotool windowactivate $id 2>&1)"
    if [ -z "$error" ]; then # when it issues an error message, it fails to open
        exit 0 # if opened, stop trying
    fi
done

if ! [ "$found" = true ]; then
    $1 & # if there is no window, start a new
fi

I put this script in ~/.local/bin/ and gave it run permission (chmod +x ~/.local/bin/activate_windows.sh).

You need to install xdotool if you don't have it (sudo apt install xdotool).

So I created a shortcut for each app I use the most:

  • super+1 → ~/.local/bin/activate_windows.sh pcmanfm
  • super+2 → ~/.local/bin/activate_windows.sh firefox
  • super+3 → ~/.local/bin/activate_windows.sh lxterminal

You can create your own. To identify the classname and class of a window, run xprop | fgrep CLASS, and click on the desired window.

Whenever I want to open firefox, for example, I type super+2, regardless of position of firefox in the taskbar.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .