Ubuntu – How to set keyboard layout for the guest session

guest-sessionkeyboard-layout

First, my ultimate goal is the same as in this question. I am a Dvorak user, but I want QWERTY, not Dvorak, to be the default keyboard layout in a guest session. If you know a direct answer to that instead of to the question below, that will also be appreciated.


I can change the keyboard layout to QWERTY with setxkbmap -layout us.

Some googling tells me that if I create a shell script /etc/guest-session/prefs.sh, it will be run when the guest session starts.

So I created a prefs.sh file containing just that command:

setxkbmap -layout us

What I expected to happen was to be able to run a guest session and automatically have the keyboard layout set to QWERTY. What actually happened was that when I tried running a guest session, it simply failed and brought me back to the login screen.

I must be misunderstanding something, but I don't know what. Any ideas?

If relevant: I'm using Ubuntu 12.04.

Best Answer

  • The way you did it, the command was run prematurely, i.e. before the actual start of the guest-session. Try this instead:

    echo 'setxkbmap -layout us' >> $HOME/.profile
    

    I just rewrote the tutorial about customizing guest sessions. It might help you understand it better.

    Edit:

    This has become more tricky on later Ubuntu versions. These lines in /etc/guest-session/prefs.sh work for me on Ubuntu 15.10:

    echo "gsettings set org.gnome.desktop.input-sources sources \"[('xkb', 'se'), ('xkb', 'us')]\"" >> $HOME/.profile
    echo "gsettings set org.gnome.desktop.input-sources current 1" >> $HOME/.profile
    

    The ('xkb', 'se') value is my system default (a Swedish keyboard layout). So basically I set a list with my system default and the keyboard layout I want to use in the guest sessions - English (US). Then I tell the system to make the second value in the list the current keyboard layout. 0 (zero) would have been the first value.