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.


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



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 = Gio.Settings.new("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()

if arguments.show:
    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.


You can use gsettings command with custom shortcuts. Read more details here: https://askubuntu.com/a/984981/6193

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.