2

What I'm trying to do is set up a udev rule for my HP headphones (usb) with the aid of several tutorials out there.

Created a file ( 90-local.rules ) in /etc/udev/rules.d and added the following:

ACTION="add",SUBSYSTEM="usb", ATTR{vendor}=="Hewlett-Packard", RUN+="sh /home/alex/Scripts/usb.sh"

The problem is nothing happens when I connect the headphones! What am I doing wrong?

note: I did restart udev and the script works also, so it's not that

5
  • Do this corresponds with the output of monitoring udevadm? Sep 2, 2012 at 20:48
  • If by 'this' you mena the vendor, yes Sep 2, 2012 at 20:50
  • What exactly is the usb.sh script doing?
    – user1686
    Sep 3, 2012 at 9:36
  • just a simple notify-send call Sep 3, 2012 at 10:35
  • Here's the output of udevadm info -a -p /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2:1.3/input/input29 if it helps: pastebin.com/95swJYhF Sep 3, 2012 at 10:38

2 Answers 2

0

Your udev rule is fine. The problem is that your script, as well as udev itself, runs

  1. as root – not as your own user account;
  2. as a service – outside your login session;

and therefore do not have access to your X11 display, or your DBus session bus.

Remember that Linux, as Unix, has supported multiple concurrent login sessions from day one, so there isn't "the user"; there can be multiple users having multiple X11 displays and multiple DBus buses (which might not even have an X11 server attached).

A common workaround is to make the script always choose the first X11 display (by setting DISPLAY=":0" inside the script). However, this is not guaranteed to work – even a single-user PC can have two or more X11 displays running (for example, your own desktop might be at :1, while :0 might be the login screen or not running at all).

3
  • changed my rule to: ACTION="add",SUBSYSTEM="usb", ATTR{vendor}=="Hewlett-Packard", RUN+="su alex -c 'DISPLAY=:0 notify-send test'" but still nothing. Note: running "su alex -c 'DISPLAY=:0 notify-send test" as root works. Any ideas? Sep 3, 2012 at 11:22
  • @user1233963: Try /bin/su, /usr/bin/su, or whichever is right for your system.
    – user1686
    Sep 3, 2012 at 11:50
  • It's /bin/su, tried it, no change. Other ideas? Sep 3, 2012 at 12:00
0

Try this out first by doing Alt-F2 and in the box there do something like /bin/sh -c "DISPLAY=:0.0 /usr/bin/notify-send foobar" Note all complete paths, and note double quotes around shell command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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