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.

As my keyboard layout doesn't suit me, I run xmodmap on login. The script is named .profile and it runs OK, but it breaks the Unity interface.

I want to know where to put the xmodmap line so that it executes on my login and doesn't break anything.

I have already tried putting it in the .bash_login and .bash_profile files, without success (xmodmap doesn't set my keyboard).

What are my options?

share|improve this question
3  
How does it break the unity interface? –  djeikyb Jul 23 '11 at 0:28
add comment

3 Answers 3

The correct place to put xmodmap ~/.Xmodmap (so that your changes are read at startup) is in ~/.xinitrc (see explanation below), although you could alternately place the xmodmap command as a startup item (/usr/bin/xmodmap /home/user/.Xmodmap). I can say that for 12.04 (and presumably 12.10) that these two alternatives definitely do work, as either way they are read after you log in with lightdm. (I changed Return to Right Shift, and the change only took effect after entering my password and logging in).

Please note: if you are on Xfce, it is noted on the official Xfce FAQ that you may have to create a startup item instead of using ~/.xinitrc, and that you might have to delay the execution so the xmodmap changes are not overwritten by setxkbmap. You can use a delay to achieve this in your startup entry:

/bin/bash -c "sleep 20; /usr/bin/xmodmap /home/$USER/.Xmodmap"

(For the startup entry it is necessary to specify absolute paths)

Each time setxkbmap is run to change keyboard layout, you will have to run xmodmap ~/.Xmodmap again in the terminal.

Creating ~/.xinitrc

Create a file in your home folder called .xinitrc with

touch .xinitrc

and place in it:

xmodmap ~/.Xmodmap

Your Xmodmap file should not have entries in the xmodmap -e " " style as that is used in the terminal for temporarily setting the values. It must have entries in this format:

keycode 65 = Tab
keycode 23 = Space

It is often confusing which of the various X files (such as .xprofile, .xinitrc, etc) are read at startup, but .xinitrc does seem to be still read under 12.04, whereas .Xmodmap or .xinputrc are not read by themselves.

share|improve this answer
    
Note that if you make your changes with xmodmap -e '..., you can retrieve the right format for xmodmap .Xmodmap with xmodmap -pke, which prints out the current mapping - though you'll want to filter this down to just the lines that apply to the change you made. –  Barry Kelly Sep 26 '13 at 14:08
add comment

I don't have the unity interface in front of me just now, but try clicking the Applications button on the launcher, then type startup. There should be an app called Startup Applications (or some such). Click it and add your xmodmap command (eg xmodmap .Xmodmap).

share|improve this answer
    
I tried that a while ago but it didn't work out for me. I'm on windows right now but I'll try again later and I report here if it works. thx –  Thiago Moraes Jul 24 '11 at 4:05
2  
@Thiago Moraes Does this basic command work (if not, post the error)? xmodmap .Xmodmap –  djeikyb Jul 28 '11 at 2:18
    
+1 this does work. To be more explicit I used the full path for .Xmodmap –  pwned Nov 8 '13 at 5:52
add comment

Putting xmodmap changes in ~/.bashrc or /etc/bash.bashrc doesn't break anything.

Only downside is that one has to open a terminal after each boot to get it activated.

share|improve this answer
2  
I'm already doing that, but the problem is that at every terminal I open, this command gets executed. It's only a moment but it's a little annoying and I would prefer a real solution. thx anyway –  Thiago Moraes Jul 24 '11 at 4:04
add comment

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.