Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm using English, Russian and Armenian keyboard layouts. When I'm trying to change layout it's changing "en" -> "am" -> "ru" -> "en"... I want to use Left Alt + Shift to toggle "en" and "am", and Right Alt + Shift to toggle "en" and"ru". Can you help me?

share|improve this question
    
Actually there are limited options keys to change the layout. But it may help you.. 1.Search Keyboard Layout in dash and open. 2. Go to Layouts tab and click Options... button. 3. In Keyboard Layout Options Window, expand Key(s) to change layout list. 4. Now check the most appropriate option which best soot for you. You can check multiple keys to Change keyboard option. Hope it helps you. I couldn't find any other way to set custom keys to do so.. –  Saurav Kumar Oct 5 '13 at 10:45
    
I've changed keys to Alt+Shift, but both sides changing layout with same order․ –  David ZIP Oct 5 '13 at 10:53

1 Answer 1

up vote 0 down vote accepted

There are many shortcuts to choose to switch between keyboard layouts, but none fits with what you want.

Anyway, it can be done using a bash scripts and two custom shortcuts.

First, create the script, let's call it change_layouts:

#!/bin/bash
#script to switch between two keyboard layouts

if [ $# -ne 2 ];then
    echo "Usage: `basename $0` first_layout second_layout"
    echo "   ex: change_layouts us ru"
    exit
fi

first_layout=$1
second_layout=$2

if [ -z "$(ls -l /usr/share/X11/xkb/symbols | grep ^- | awk '{print $9}' | grep $first_layout)" ]; then
    echo "Error: Doesn't exists ant keyboard layout called '$first_layout'."
    exit
fi

if [ -z "$(ls -l /usr/share/X11/xkb/symbols | grep ^- | awk '{print $9}' | grep $second_layout)" ]; then
    echo "Error: Doesn't exists ant keyboard layout called '$second_layout'."
    exit
fi

if [ "$first_layout" = "$second_layout" ]; then
    echo "Error: The arguments (keyboard layouts) must to be different."
    exit
fi

current_layout=$(gsettings get org.gnome.libgnomekbd.keyboard layouts)

if [ "$current_layout" = "['$first_layout', '$second_layout']" ]; then
    gsettings set org.gnome.libgnomekbd.keyboard layouts "['$second_layout', '$first_layout']"
else 
    gsettings set org.gnome.libgnomekbd.keyboard layouts "['$first_layout', '$second_layout']"
fi

Save the script in your ~/bin directory and don't forget to make it executable:

chmod +x ~/bin/change_layouts

Now you can test the script in terminal. Run it more times to see how it works.

Second, add your custom shortcuts. Go to System SettingKeyboardShortcutsCustom Shortcuts and follow the instructions from the below image:

add custom shortcut

share|improve this answer
    
And what to do with default shortcuts? (Layout>Options>Keys to change layouts). I'm tried to disable it, but layout doesn't changed anymore, also tried to set Alt+Shift but it changes layout by same order. –  David ZIP Oct 6 '13 at 6:04
    
@DavidZIP I disabled everything in Layout>Options>Keys to change layouts. And be careful what shortcuts do you use for the script. The system doesn't make differences in this case between Left Alt and Right Alt as you probably wish. I used Shift+Alt+Left Arrow and Shift+Alt+Right Arrow. See the image above. –  Radu Rădeanu Oct 6 '13 at 6:14
    
I'm using Alt+Shift L and Alt+Shift R, also now I'm disabled keys to change layouts, but it still not working. –  David ZIP Oct 6 '13 at 7:40
    
@DavidZIP As I said, the system doesn't make differences in this case (for custom shortcuts) between Left Alt and Right Shift, Left Shift and Right Alt, or Left Ctrl and Right Ctrl as you probably wish. Use Arrows keys for example. –  Radu Rădeanu Oct 6 '13 at 8:01
    
Ok, now it works, but when I'm changing am to en, and then trying to change to ru I must use Alt+Shift+Right TWICE to change layout. –  David ZIP Oct 6 '13 at 8:42

Your Answer

 
discard

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.