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?
Asked
Active
Viewed 1,043 times
1 Answers
0
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 Setting → Keyboard → Shortcuts → Custom Shortcuts and follow the instructions from the below image:

Radu Rădeanu
- 169,590
-
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 Abgaryan Oct 06 '13 at 06: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
andRight Alt
as you probably wish. I usedShift+Alt+Left Arrow
andShift+Alt+Right Arrow
. See the image above. – Radu Rădeanu Oct 06 '13 at 06: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 Abgaryan Oct 06 '13 at 07:40
-
@DavidZIP As I said, the system doesn't make differences in this case (for custom shortcuts) between
Left Alt
andRight Shift
,Left Shift
andRight Alt
, orLeft Ctrl
andRight Ctrl
as you probably wish. UseArrows keys
for example. – Radu Rădeanu Oct 06 '13 at 08: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 Abgaryan Oct 06 '13 at 08:42
-
@DavidZIP If this is a problem, to fix this, use in Custom Shortcuts windows these commands:
change_layouts am us
, respectivelychange_layouts ru us
(useus
at the end of the commands). – Radu Rădeanu Oct 06 '13 at 09:07
Keyboard Layout
in dash and open. 2. Go toLayouts
tab and clickOptions...
button. 3. InKeyboard Layout Options
Window, expandKey(s) to change layout
list. 4. Now check the most appropriate option which best soot for you. You can check multiple keys toChange keyboard option
. Hope it helps you. I couldn't find any other way to set custom keys to do so.. – Saurav Kumar Oct 05 '13 at 10:45