Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question
    
Do this corresponds with the output of monitoring udevadm? –  Tom Wijsman Sep 2 '12 at 20:48
    
If by 'this' you mena the vendor, yes –  user1233963 Sep 2 '12 at 20:50
    
What exactly is the usb.sh script doing? –  grawity Sep 3 '12 at 9:36
    
just a simple notify-send call –  user1233963 Sep 3 '12 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 –  user1233963 Sep 3 '12 at 10:38
add comment

2 Answers

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).

share|improve this answer
    
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? –  user1233963 Sep 3 '12 at 11:22
    
@user1233963: Try /bin/su, /usr/bin/su, or whichever is right for your system. –  grawity Sep 3 '12 at 11:50
    
It's /bin/su, tried it, no change. Other ideas? –  user1233963 Sep 3 '12 at 12:00
add comment

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.

share|improve this answer
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.