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 want to set the key to toggle the language of my keyboard to "`" but I don't have this option at "Keyboard Layout" in Unity, in Ubuntu 12.04. I have already seen this answer but it doesn't help me. Can you please direct me as to how to use setxkbmap? (if that's the way to go). Thanks!

share|improve this question
    
How do you presently toggle language of your keyboard? –  saji89 May 24 '12 at 16:29
    
Alt+Shift. I have chosen it using the method in the answer below, by @Reverendj1. –  Dimitris Tzortzis May 24 '12 at 21:11

2 Answers 2

Here is an easy way to do it, but you are limited to what shortcuts you can use. Open "System Settings" -> "Keyboard". Click "Layout Settings", near the bottom. Click the + button to add any languages you need. Then click "Options..." There you can set the key combos you need, by selecting "Key(s) to change layout". If you want, you can also choose to use a keyboard LED to show when you are using your alternative layout (such as scroll lock) under "Use keyboard LED to show alternative layout".

Here is the slightly more involved way, but will give you more flexibility for the key combination. First, copy and paste this script I wrote and name it something like kb_toggle.sh. Make sure to edit LANG1 and LANG2 to be the keyboard layout codes you need.

#!/bin/bash

LANG1="us"
LANG2="de"
CURRENT_LANG=$(setxkbmap -query | tail -n 1 | cut -f6 -d ' ')
if [ "$CURRENT_LANG" = $LANG1 ]; then
    setxkbmap $LANG2
else
    setxkbmap $LANG1
fi

make the file by right-clicking on it -> "Properties" -> "Permissions" tab, then select "Allow executing file as program.

Now, open "System Settings" -> "Keyboard" -> "Shortcuts" tab and select "Custom Shortcuts". Click the + button on the bottom and name the shortcut "Keyboard Toggle" or whatever you want, really. Then give the full path to the script you made earlier in the command box. Hit Apply. Click where it says "Disabled" then you can set the shortcut to whatever you want by clicking your key combination!

One more thing. I don't think it will let you set it to a single key, like "", you may have to do SHIFT+ or something like that.

share|improve this answer
    
@Reverenjd1, thanks for replying. I already used this method to choose my current combination of keys to change layout (I'm using Alt+Shift). I want however a different way to toggle layouts, one that is not offered in those settings. –  Dimitris Tzortzis May 24 '12 at 21:12
    
There you go. I updated the answer. –  reverendj1 May 24 '12 at 21:43
    
Wow, thank you for your effort! That is great. I will still leave the question un-answered for a while though, just in case anything new comes up, and choose your answer in a couple of days. Thanks a lot! –  Dimitris Tzortzis May 25 '12 at 12:07

First: Thank you so much Reverendj1 for your script -- you rock! I've been struggling to find an answer as to why the "key(s) to change layout" selections are being totally ignored. As Dimitris said, it's not an answer, but it's a good work around.

Important: I did have to change one things on your script.
-- In 12.04 my final line of the setxkbmap -query output prints "options: grp:...". So, I used a pipe to grep "layout" instead of the "tail -n1" command. So the script looks as such:

#!/bin/bash
LANG1="us"
LANG2="de"
# CURRENT_LANG=$(setxkbmap -query | tail -n 1 | cut -f6 -d ' ') # OLD LINE
CURRENT_LANG=$(setxkbmap -query | | grep "layout" | cut -f6 -d ' ')
if [ "$CURRENT_LANG" = $LANG1 ]; then
    setxkbmap $LANG2
else
    setxkbmap $LANG1
fi

NB: If someone changes the number of spaces in the line "layout: us" then the -f6 option will fail to return "us". That will likely have to be fixed in the future.

Again, thank you so much for this fix. I can work much more efficiently now. ** Sorry, this was overly wordy

share|improve this answer

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.