Is there a way to change the currently active keyboard layout in Cinnamon, from command line?

The setxkbmap solution that most of the guides suggest, doesn't quite work as it is supposed to: If it is called, the language indicator in Cinnamon itself dissapears, and the existing combinations configured in Cinnamon do not work any more. To restore this functionality, one has to go to the settings and re-enable any of the keyboard layout setting.

Additionally, the way setxkbmap seems to change the layout is of a nature of being lower level than Cinnamon seems to like: for example if you change a layout to a non-latin one, using setxkbmap, the default key combinations in the whole system stop working. (easily tested with Ctrl-C). This never happens with the native layout switching from within Cinnamon. It appears that setxkbmap operates at a lower level than what most applications expect.

Is there a way to change the layout the native, Cinnamon (or gnome, since it's based on it?) way and keep the keyboard combinations working?

(Another solution usually proposed is gsettings set org.gnome.desktop.input-sources current 0, which does not work either in current Cinnamon (nothing happens)).

I have of course, tested all the possible indexes, up to 10, even though I have only 3 layouts added currently. The mentioned variable does not seem to change either when the layouts are changed manually. I have also tried the similar variable that exists in Cinnamon environment, org.cinnamon.desktop.input-sources, but it does not affect anything either (in exactly the same way as the gnome version).

  • What about gsettings set org.gnome.desktop.input-sources current 1 ? – Gunnar Hjalmarsson Oct 24 '17 at 17:01
  • I have of course tested different values, I have updated my question. – Cray Oct 25 '17 at 16:05
  • At a terminal prompt, one may use the SUPER-SPACE shortcut to cycle through your keyboard layouts. Will this work for you? Or must it be a solution for scripts, alone? – TheGeeko61 Oct 25 '17 at 16:29
  • Well, if that does not work for switching layout, Cinnamon seems to do it its own way, differently from Unity and GNOME. I'm not able to tell how. – Gunnar Hjalmarsson Oct 25 '17 at 18:50

The best solution currently is to use this external program (xkb-switch) that accepts command line arguments and script it into xbindkeys or something similar.

Although unofficial, external, and written in a compilable language, it is actually pretty easy to install since it has almost no dependencies.


$ xkb-switch --help

Usage: xkb-switch -s ARG            Sets current layout group to ARG
       xkb-switch -l|--list         Displays all layout groups
       xkb-switch -h|--help         Displays this message
       xkb-switch -v|--version      Shows version number
       xkb-switch -w|--wait [-p]    Waits for group change and exits
       xkb-switch -W                Infinitely waits for group change
       xkb-switch -n|--next         Switch to the next layout group
       xkb-switch [-p]              Displays current layout group

Use as:

xkb-switch -s us
xkb-switch -s de

This solution:

  • Works from command line.
  • Is fast, invocation of this program does not introduce any delay (as opposed to switching layout setxkbmap).
  • Correctly switches the built-in layout indicator in the tray icon area. (The indicator does not dissappear or stops working, as with setxkbmap.)
  • Does not screw up keymap on the lockscreen, preventing entering the right password if the wrong layout was chosen before locking (as does setxkbmap).
  • Does not modify the main key combinations like Ctrl-C, Ctrl-V: they still work with the same keys even in different layouts (being different from, well you get the idea, setxkbmap).
  • Honors all the Cinnamon layout mechanics, like the setting of either using the same layout for all windows or individual layout per-window. (Take a guess if setxkbmap does that?)

The installation instructions are on the Github.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.