Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a few language keyboard layouts installed in 12.04. I am using Ctrl-Shift keyboard shortcut for switching between language layouts. Such switching method takes a lot of my time.

Is there any possibility to set up a different keyboard shortcut for each language keyboard layout?

For example:

Ctrl-Shift-1 (English layout),

Ctrl-Shift-2 (Polish layout),

Ctrl-Shift-3 (Italian layout), etc.

share|improve this question
up vote 2 down vote accepted

Simple: go to keyboard settings, click on "Shortcuts", and add "Custom shortcut". For each shortcut, add the respective command that chooses one layout. The commands are

setxkbmap -layout en
setxkbmap -layout pl
setxkbmap -layout it


share|improve this answer
This is magic :-) Thank you !!!!! – Vitaliy Sep 30 '12 at 15:51

The problem with January's solution is that it doesn't play nicely with Unity's indicator.

Below is a small python script that you can use instead of setxkbmap:

#!/usr/bin/env python

import argparse
from gi.repository import Gio

setting ="org.gnome.desktop.input-sources")
keymaps = [keymap for (_, keymap) in setting['sources']]

parser = argparse.ArgumentParser(prog='keymap_cycle', description='Cycle through a subset of enabled keymaps.')
group = parser.add_mutually_exclusive_group(required=False)
group.add_argument('-s', '--show', action='store_true', help='show available keymaps')
group.add_argument('-k', '--keymaps', default=','.join(keymaps), help='cycle through keymaps (default: %(default)s)')
arguments = parser.parse_args()

    print 'Available keymaps: %s' % ', '.join(keymaps)
    cycle = arguments.keymaps.split(',')

    current_language = keymaps[setting['current']]

        current_cycle_index = cycle.index(current_language)
        desired_cycle_index = (current_cycle_index + 1) % len(cycle)
    except ValueError:
        desired_cycle_index = 0

    desired_language = cycle[desired_cycle_index]

        desired_language_index = keymaps.index(desired_language)
        setting['current'] = desired_language_index
    except ValueError:

Save it to $HOME/.local/bin (or whatever other place you like), then chmod +x it. Add all the keymaps you want via standard Ubuntu's keymap configuration screen.

Then the original question could be solved by binding a shortcut for each of the following commands:

keymap_cycle --keymap en
keymap_cycle --keymap pt
keymap_cycle --keymap it

But it can do even more! For example keymap_cycle --keymap en,it would cycle keymaps like this en->it->en->it... on each invocation.

To show all available keymaps you have added via Ubuntu's keymap configuration screen run keymap_cycle --show.

Kudos to @bjonen and his answer for the gsettings magic insight.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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