I have a usb keyboard that I plug in into my desktop at work. While using it tend to manually set the following setxkbmap option:

setxkbmap -option compose:ralt
setxkbmap -option ctrl:swap_rwin_rctl
setxkbmap -option ctrl:swap_lwin_lctl

Since I do it frequently I wanted to automate the process by using a udev rule. The following rule matches the event when I plug-in the keyboard:

ACTION=="add", SUBSYSTEM=="usb", DRIVER=="usb", ATTRS{idVendor}=="046a", ATTRS{idProduct}=="0023", RUN+="/home/cutuchiqueno/.local/bin/kbd_udev", OWNER="cutuchiqueno"

the script which is RUN contains the three lines from the beginning of this question:

setxkbmap -option compose:ralt
setxkbmap -option ctrl:swap_rwin_rctl
setxkbmap -option ctrl:swap_lwin_lctl
echo `date +%T` >> /home/cutuchiqueno/udevtest

(I added the last line just for debugging purpose). Unfortunately the options are not chainged. I can imagine that is has something to do with environment parameters though I don not really know how to approach the problem.

Two modifications made this particular case working:

the kbd script needed a DISPLAY:0.0 addition

the udev rule reacted to an event that was too early. I changed subsystem to input.

and everything worked well.

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.