I need to provision several Ubuntu 14.04/14.10 desktops. Most things I've been able to provision easily because they can be set in config files or from the command line.

But I'm having trouble with 2 things, setting the available languages and setting the keyboard shortcuts for switching between the languages. I know how to do them from gnome-control-center

  1. Set the available languages

    Region & Language > Input Sources > English (US) + German + Italian

  2. Set the keyboard shortcuts for switching languages

    Shortcut Settings > Typing > Switch to next source (Super+Escape), Switch to previous source (Shift+Super+Escape)

But I don't know how to do from config files or command line, so I can't provision it automatically.


The keys

The keys you are looking for are:

  1. for editing the input sources:

    org.gnome.desktop.input-sources sources
  2. for editing the keyboard shortcut for switching languages forward:

    org.gnome.desktop.wm.keybindings switch-input-source
  3. for switching input source backward:

    org.gnome.desktop.wm.keybindings switch-input-source-backward

The commands to edit the settings

Example commands to edit the three from command line:

  1. For editing the input sources, to set the input sources as mentioned in your question:

    gsettings set org.gnome.desktop.input-sources sources "[('xkb', 'us'), ('xkb', 'it'), ('xkb', 'de')]"
  2. to set the switch- shortcut key combination to Ctrl+space

    gsettings set org.gnome.desktop.wm.keybindings switch-input-source "['<Primary>space']"
  3. to set the switch- shortcut key combination to switch backward Shift+Super+space

    gsettings set org.gnome.desktop.wm.keybindings switch-input-source-backward "['<Shift><Super>space']"

The commands to get the current settings

gsettings get org.gnome.desktop.input-sources sources
gsettings get org.gnome.desktop.wm.keybindings switch-input-source
gsettings get org.gnome.desktop.wm.keybindings switch-input-source-backward

How to find these keys

You can search for keywords in the database by listing all keys with the command:

gsettings list-recursively

which will list all existing keys, or (which I regularly do) install dconf-editor and simply find your keyword(s) with Ctrl+F.


As requested in a comment, I added a small script to walk through the input sources from command line:

#!/usr/bin/env python3
import subprocess
import sys

src = sys.argv[1]
key = "org.gnome.desktop.input-sources"
get = lambda cmd: subprocess.check_output(["/bin/bash", "-c", cmd]).decode("utf-8").strip()

src_list = len(eval(get("gsettings get "+key+" sources")))-1
current = int(get("gsettings get "+key+" current").split()[-1])
if src == "+":
    set_new_value = "gsettings set "+key+" current "+(str(current+1) if current <  src_list else "0")
elif src == "-":
    set_new_value = "gsettings set "+key+" current "+(str(current-1) if current > 0 else str(src_list))
subprocess.Popen(["/bin/bash","-c", set_new_value])

To run it

  1. Save the script, into an empty file, as switch_source.py
  2. Run it by the command:

    python3 /path/to/switch_source.py +

    to go to the next input source, and

    python3 /path/to/switch_source.py -

    to go to the previous one

  • I will test this out and report back. 'switch-input-source' would be for 'Switch to next source', how can I find the key for 'Switch to previous source'? – user779159 Apr 2 '15 at 15:35
  • How did you find these keys btw, is there a simple way to tell which keys correspond to which settings in gnome-control-center? Like is it documented somewhere or is there a technical way to find out? – user779159 Apr 2 '15 at 15:35
  • @user779159 edited my posts with answers to both comments :) – Jacob Vlijm Apr 2 '15 at 16:03
  • Setting the sources works great, thanks! But switching isn't working. From the command line doing setxkbmap de works fine, but not with keyboard shortcuts, nothing happens. Looking through the settings I see org.gnome.settings-daemon.peripherals.keyboard input-sources-switcher 'off', could it be related? – user779159 Apr 2 '15 at 20:03
  • 1
    @Fabby I just need an excuse to pythonize something now and then :). – Jacob Vlijm Apr 6 '15 at 18:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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