Ubuntu – Stateless layout switching in Ubuntu 14.04

13.1014.04gnome-settings-daemonkeyboardkeyboard-layout

screenshot

I use extensively two keyboard layouts (latin for English, and cyrillic for Ukrainian and Russian), and it bothers me to experience my mode errors because of the additional bit of UI state: the current layout.

I used to eliminate them completely by using stateless layout switching, whereby one has no next layout action (as such an action is based on the current state, which is easy to forget for the user, and so leads to errors), rather only two actions:

  1. enable latin layout;
  2. enable cyrillic layout.

This was trivially accomplishable in pre-Saucy releases. As illustrated on the screenshot above.

However, that settings window was destroyed in Saucy.

How do I get my stateless switching now?

Best Answer

This command will set layout to the first one (It works nicely with Unity/Gnome Indicator, Ubuntu 13.10/14.04):

gsettings set org.gnome.desktop.input-sources current 0

You can use tweak tools, gnome action, compiz action plugin..etc to create a keyboard shortcut for it.

Layouts are indexed starting from 0. So you can make shortcut for any layout in the list.

You can use this to create complex script for last layout without giving an index:

 gsettings get org.gnome.desktop.input-sources sources

Like:

 gsettings set org.gnome.desktop.input-sources current $(($(gsettings get org.gnome.desktop.input-sources sources | grep -Po "'[[:alpha:]]+'\)" | wc -l)-1))
Related Question