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 run a shell command or script that will configure each of my Ubuntu Precise boxes to use the Dvorak keyboard layout as the default (and only) layout. With earlier versions, I was able to set the XKBVARIANT in /etc/default/keyboard but when I make this change in Precise (and reboot), the keyboard layout appears to be unaffected (both in console and in gnome).

I tried also setting the XKBMODEL to pc105 and XKBLAYOUT to us, but that did not seem to help.

I know I can set the layout for gnome using the 'keyboard layout' tool... but I want the change to affect the console, and I want to automate the process. How can I accomplish this?

Edit:

To clarify, I want to know how I can cause to change (using only a script or command-line) the keyboard layout to be Dvorak as the default and only keyboard layout for both Gnome and the console. I want this change to be persistent (survive reboots), just as it is when the change is made through the Keyboard Layout tool.

Edit:

Let me put it another way. If I had installed the operating system myself (which I did not because the OS was installed by the virtual machine infrastructure), I could have selected the desired keyboard layout at install time, and that layout would be applied persistently, system-wide. How can I change the layout to appear as if I had set it during the install process?

share|improve this question
    
I've discovered that i can edit /etc/default/keyboard setting XKBVARIANT="dvorak" and XKBLAYOUT="us" and then run sudo dpkg-reconfigure console-setup -u and reboot, and the console will start up with the dvorak layout. That's half the problem. Now how to do the same for the X session? –  Jason R. Coombs May 21 '12 at 14:25
    
It seems that if I run udevadm trigger --subsystem-match=input --action=change, the X session does adopt the settings as defined in /etc/default/keyboard, but if I reboot, the setting is lost. It appears the readme in /usr/share/doc/keyboard-configuration/README.Debian is incorrect. This may be a bug in Precise. –  Jason R. Coombs May 21 '12 at 14:36

4 Answers 4

I too use Ubuntu 12.04 and have stuggled with this issue. Using Jason Coombs' answer to his own question as a starting point, I was able to use /etc/default/keyboard to set my keyboard options (for me, ctrl:nocaps and compose:menu) and have that persist across reboots for consoles. However, the setting would be ignored by LightDM/Unity upon reboot. To clarify, I have not set any keyboard preferences from within Unity, so Unity should be defaulting to the system default keyboard settings, but it is not using the keyboard options for some reason.

I noticed that if I run the following command after logging in, Unity suddenly begins to recognize my system default keyboard options:

setxkbmap

I do not supply any parameters to setxkbmap, I merely invoke it with no options and it reads and applies the system default map.

To make this happen automatically when any user logs in (at least, any user with a Gnome or Unity desktop), I have made the following setxkbmap.desktop file that I placed in the /etc/xdg/autostart/ directory:

[Desktop Entry]
Type=Application
TryExec=/usr/bin/setxkbmap
Exec=/usr/bin/setxkbmap
Hidden=false
NoDisplay=true
X-GNOME-Autostart-enabled=true
Name[en_US]=System Keyboard Fix
Name=System Keyboard Fix
Comment[en_US]=Apply system-wide keyboard settings to the session
Comment=Applies system-wide keyboard settings to session

This fix seems to make the keyboard options consistent system-wide, with the exception of the brief period that LightDM has control of my screen before I log in.

share|improve this answer
    
getting there! Thanks for the info. –  Jason R. Coombs May 22 '13 at 23:59

!!! Unfinished answer !!! (remove this warning if you know how to improve this answer)

You can use the command setxkbmap. For example

setxkbmap de

sets the current layout to german. With

setxkbmap us

you can set it to the US layout.

Warning: I think this command resets also other language options. For example the language icon disappears, when I run this command. Therefore it is also very difficult to change back to a layout with Latin letters, if you changed to something like Cyrilic, Chinese, Greek etc. But the command setxkbmap might be a good hint to continue research how to toggle the layout.

share|improve this answer
    
I can use 'setxkbmap us dvorak' and that does set the layout for the current X session, but when I restart the PC, the layout has reverted. I'd like it to be persistent, just like when using the keyboard layout tool. I would also like it to affect the console if possible. –  Jason R. Coombs May 21 '12 at 13:56

If you want to change it in tty consoles (those accessible through Ctrl+Alt+F1 or F2, ...) it is:

loadkeys fr

for french or this one for US keyboard:

loadkeys us

Though, I'm not sure if it works for consoles launched in X.org/graphical mode (aka the Console application from Unity/Gnome or Konsole from KDE). You should give it a try.

share|improve this answer
    
Loadkeys does work in the interactive console, but it does not affect Gnome terminals or other Gnome applications. I do appreciate the tip, though, as this might be part of a two-step process necessary to affect both X and the console. Where would this setting go in order to affect all consoles (to make this the default layout), such as if this layout had been selected at install time? –  Jason R. Coombs May 21 '12 at 14:05
    
To do it globally and keep the setting across reboot you have to reconfigure the console with sudo dpkg-reconfigure console-data. If you are adding a new language to a, let's say, english-only system, you may have to launch sudo dpkg-reconfigure locales before (and maybe edit /var/lib/locales/supported.d/local, see this post) –  maximd May 26 '12 at 7:50
    
And for X, you should try set-language-env -l fr (for French), see set-language-env's manpage –  maximd May 26 '12 at 8:06
setxkbmap -option grp:alt_shift_toggle en
share|improve this answer
    
Why do you need sudo? –  lumbric May 17 '12 at 15:31
    
yes you don't need sudo. –  Subv3rsion May 17 '12 at 15:43
    
I don't want to change the setting once. I the setting to take effect system wide. Also, I don't think I need the alt-shift toggle option because I want only one keyboard layout. I've tried to clarify the question by describing it a couple of different ways. –  Jason R. Coombs May 21 '12 at 14:02

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.