Topic: Switching Keyboard Layouts - the EASY way!

I was frustrated at how I had to bind a different keybinding to each layout I wanted to switch to.  So I came up with a simple script which simply checks a file and changes the keyboard layout accordingly.  I needed to switch between US and US International, so those are the two layouts my script checks for.  However, this can easily be adapted for more than two layouts.

Here's the script:

#!/bin/bash
KEYBOARD=`cat ~/.keyboard`
test "$KEYBOARD" = "us"
RETURN=$?
if [[ $RETURN -eq 0 ]]
then
setxkbmap us intl
echo "us intl" > ~/.keyboard
exit
fi
if [[ $RETURN -eq 1 ]]
then
setxkbmap us
echo "us" > ~/.keyboard
exit
fi

To use this, you need to create the .keyboard file.  So open up a terminal and type in

echo "us" > .keyboard

That's it!

To use this for more than two layouts, you would add another RETURN variable (like RETURN2) and test for equality with another of your keymaps.  Then, you'd add some more test statements checking first if RETURN is true, and then if RETURN2 is true.  If neither is true, you should switch to the third layout.

Now just bind this script to a keyboard shortcut in Openbox and you're good to go! smile

Last edited by chaanakya (2011-01-10 21:34:23)

Check out Musik - an easy-to-use text-to-music converter!
Join SpiderOak using this link and get an extra 1 GB free: https://spideroak.com/download/referral … 660e787ff1

Re: Switching Keyboard Layouts - the EASY way!

Or you could just put something like this in /etc/default/keyboard:

XKBMODEL="pc105"
XKBLAYOUT="us,us intl"
XKBVARIANT=""
XKBOPTIONS="grp:switch,grp:alt_shift_toggle"

This allows you to change between layouts like in Windows, by pressing Alt+Right_Shift.

Re: Switching Keyboard Layouts - the EASY way!

Oh... tongue  lol big_smile

Last edited by chaanakya (2011-01-10 22:21:46)

Check out Musik - an easy-to-use text-to-music converter!
Join SpiderOak using this link and get an extra 1 GB free: https://spideroak.com/download/referral … 660e787ff1

Re: Switching Keyboard Layouts - the EASY way!

I'm assuming you can just change the

alt_shift_toggle

to change the keybinding?

Check out Musik - an easy-to-use text-to-music converter!
Join SpiderOak using this link and get an extra 1 GB free: https://spideroak.com/download/referral … 660e787ff1

Re: Switching Keyboard Layouts - the EASY way!

Yes. You can find a list of options in the following file: /usr/share/X11/xkb/rules/base.lst.

Re: Switching Keyboard Layouts - the EASY way!

Eh...oh well...at least I get the satisfaction of writing a script... wink

Check out Musik - an easy-to-use text-to-music converter!
Join SpiderOak using this link and get an extra 1 GB free: https://spideroak.com/download/referral … 660e787ff1

Re: Switching Keyboard Layouts - the EASY way!

As for me I prefer this easier steps;
-go to autorun.sh (open box)
-add this line

## Start keyboard with 3 language mapping by Omen
setxkbmap -layout 'us,ua,ru' -option 'grp:alt_shift_toggle' &

That`s all.

Re: Switching Keyboard Layouts - the EASY way!

lol...I wrote this script before I figured out there was such an option with setxkbmap big_smile

Check out Musik - an easy-to-use text-to-music converter!
Join SpiderOak using this link and get an extra 1 GB free: https://spideroak.com/download/referral … 660e787ff1