Why won't my xmodmap command run on startup/login?

10

3

I want to run this command every time I log in (or every time I start up, if that doesn't work): xmodmap -e 'keysym Delete = Menu' -e 'keysym Menu = Delete'

I've tried many things. I put the command in System > Preferences > Startup Applications. I put it in a .sh file, marked it chmod +x and put that file in System > Preferences > Startup Applications. I put the script in /etc/init.d. I put the commands in ~/.profile. Nothing seems to work.

Finally, I put this in my ~/.profile:

touch test1
xmodmap -e 'keysym Delete = Menu' -e 'keysym Menu = Delete'
touch test2

Both test1 and test2 get created, but the keys are still not remapped. If I just copy/paste the command and run it manually, it works fine. But it won't run on login. Any ideas?

Matthew

Posted 2010-09-06T18:20:19.780

Reputation: 11 686

Answers

11

~/.profile runs early in the login sequence. If your desktop environment configures a keyboard layout, it can overwrite the settings you've just loaded.

Put your settings in a file called ~/.Xmodmap:

keysym Delete = Menu
keysym Menu = Delete

Under the default Gnome environment in Ubuntu 10.04, the next time you log in, you will be prompted as to whether to load ~/.Xmodmap. Load it, and tick “don't ask me again”. Then your .Xmodmap will be applied after the default settings.

Gilles 'SO- stop being evil'

Posted 2010-09-06T18:20:19.780

Reputation: 58 319

For Gnome 3.10 no longer loading ~/.xmodmap, I found a solution that worked at the https://bbs.archlinux.org/viewtopic.php?pid=1194968#p1194968 : disable Gnome's keyboard plugin. $ gsettings set org.gnome.settings-daemon.plugins.keyboard active false

– plnx – 2015-02-03T21:59:05.933

Thanks, this worked perfectly. Out of curiosity, how would I get back to the dialog that I checked "don't ask me again" for if I wanted to some time in the future? – Matthew – 2010-09-06T20:33:17.567

1@Matthew: Untested: launch gconf-editor, browse to /desktop/gnome/peripherals/keyboard/general, and edit the known_file_list entry to remove .Xmodmap. – Gilles 'SO- stop being evil' – 2010-09-06T21:25:57.360

This worked for me on the Ubuntu 10.10 beta back when you first answered this question. I did a fresh install of Ubuntu 10.10 yesterday, and put an identical .Xmodmap file in my home folder. When I logged back in, I got the dialog, loaded .Xmodmap, and ticked the box just like before. But it doesn't seem to be remapping the keys. I checked in gconf, and .Xmodmap is definitely in the known_file_list. Any ideas? – Matthew – 2010-09-18T16:47:59.820

This is also not working for me on Gnome 3.10.1/Archlinux. I wonder if something hasn't been adjusted in the order Gnome loads keyboard layouts. – Caleb – 2013-12-28T10:38:39.197

2

I found that in the place in Gconf-Editor mentioned above the name of your revised keyboard layout should appear twice, once under "known_file_list" and once under "update_handlers". As to why Ubuntu sometimes puts in the latter entry, and sometimes doesn't... well, it keeps you on your toes, doesn't it?

Incidentally, after a lot of research I used the above tweak to re-assign the Left Windows key. I put the following statement in my own keyboard layout to make it duplicate the Left Arrow key:-

keycode 133 = 0xFF51

(Check that those are the right codes for you by going into xev and pressing first one key then the other.)

It's only a little point, but while I'm on the Internet it gives me a convenient "Back" key - Alt+Win with the left hand. I can do it without looking.

Alan

Posted 2010-09-06T18:20:19.780

Reputation: 21

1Alan wrote: "I found that in the place in Gconf-Editor mentioned above the name of your revised keyboard layout should appear twice, once under "known_file_list" and once under "update_handlers"."

I can confirm that Alan is correct. In Ubuntu 10.10, in order for your ~/.Xmodmap file to have an effect, ".Xmodmap" has to appear in both the "known_file_list" and the "update_handlers" list under /desktop/gnome/peripherals/keyboard/general in gconf-editor.

Thanks, Alan. – None – 2011-04-03T04:49:01.473

1

Some systems look for a file named ~/.Xmodmap and execute the commands found there. Try putting these lines in that file:

keysym Delete = Menu
keysym Menu = Delete

garyjohn

Posted 2010-09-06T18:20:19.780

Reputation: 29 085