2

For example, press hotkey Ctrl+1 - select english, press Ctrl+2 - select other language etc. Any ideas?

karavanjo
  • 133

1 Answers1

3

The way unity/gnome change their language settings is through gsettings schema org.gnome.desktop.input-sources, and the key current. I've used it in several other scripts before to answer questions on Askubuntu.

Basic idea is that you run command

gsettings set org.gnome.desktop.input-sources current $1

Where $1 is the number of the language source. Language sources are ordered starting from 0, just like shown in your drown down menu with all the languages. So suppose my language order is english, chinese, russian. English is source 0, chinese is source 1, russian is source 3.

So what can one do is go to System Settings -> Keyboard -> Shortcuts -> Custom. By clicking plus mark, create 3 shortcuts, for 3 numbers. I suggest you use Ctrl+Shift+number, because Ctrl+number may be taken by an application, like firefox for it's own internal usage.

This I bind Ctrl+Shift+1 to gsettings set org.gnome.desktop.input-sources current 0 for english. Repeat same process for chinese: Ctrl+Shift+2 to gsettings set org.gnome.desktop.input-sources current 1. Repeat the same for other sources

Sergiy Kolodyazhnyy
  • 105,154
  • 20
  • 279
  • 497
  • Ah, nice option. I used directly setxkbmap but this seems more elegant... http://askubuntu.com/a/688070/16395 – Rmano Dec 11 '15 at 19:57
  • @Rmano setxkbmap works alright,too, especially with minimalistic desktops such as blackbox and openbox. I've used it couple of times and have no real complain about it. Out of the box it seems to lack chinese pinyin, which I think requires installing a package or compiling a keyboard layout. The advantage of using gsettings is that it requires starting gnome-settings-daemon which means if you have scripts linked to keyboard shortcuts set in Unity , they will be available in other desktops as well. And you can control tons of other utilities through gsettings,too – Sergiy Kolodyazhnyy Dec 11 '15 at 21:21