Home » Questions » Computers [ Ask a new question ]

Script in udev rule doesn’t run

Script in udev rule doesn’t run

I'm running Ubuntu 9.10 (Karmic Koala) on a laptop and would like NumLock to automatically toggle depending on whether my USB keyboard is plugged in (numlock on) or unplugged (numlock off).

Asked by: Guest | Views: 324
Total answers/comments: 2
Guest [Entry]

"The problem is that you probably have tested numlockx in (as it's name suggests) some X environment. X clients (GUI programs that connect to X server, e.g. Firefox or GEdit) need to know the server to connect to, and also must pass some kind of authorization. Try logging in from plain console, no matter by root or plain user, and starting some GUI application: it will show some DISPLAY related errors because it doesn't know.

To fix this you need to set environment variable DISPLAY; if you have only one X server it almost always has the address :0.

Try this at plain console: type numlockx on, and it will show ""Error opening display!"". Type DISPLAY=:0 numlockx on, and it will work (worked for me at least).

So you may set this environment variable in udev or just launch sh -c 'DISPLAY=:0 numlockx <state>'."
Guest [Entry]

It might be pure coincidence, but my udev rule started working when I named it starting with a number, eg. 80-usb-keyboard.rules.