I use Linux Mint 13 MATE, and I'm trying to set up notifications when I plug/unplug devices.
First of all, I found udev-notify package, but unfortunately it almost doesn't work for me: it works for very little time (1-2 minutes), and then, if I connect/disconnect any device, it crashes:
Traceback (most recent call last): File "./udev-notify.py", line 319, in <module> notification.show() glib.GError: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name :1.1061 was not provided by any .service files
I haven't found any solution, so I had to remove it. (filed bugreport also)
Surprizingly, there're no similar utilities I've found so far. Then I tried to write udev rules that should match all devices. I have added new file
ACTION=="add", RUN+="/bin/bash /home/dimon/tmp/device_plug.sh" ACTION=="remove", RUN+="/bin/bash /home/dimon/tmp/device_unplug.sh"
And two scripts:
#!/bin/bash export DISPLAY=":0" notify-send "device plugged" /usr/bin/play -q /path/to/plug_sound.wav &
#!/bin/bash export DISPLAY=":0" notify-send "device unplugged" /usr/bin/play -q /path/to/unplug_sound.wav &
It works, but it works very dumb. My questions are:
- How to get actual title of the device attached, the same as I can see in
lsusboutput? Currently, I just got notifications like "plugged" and "unpugged", and I can't find how can I retrieve the name of the device in my udev rule (If I can, then I'd pass it to my script as a parameter)
- Currently, too many notifications are activated. Say, when I attach my USB stick, I got about 15 notifications! But, if I run
lsusb, attached USB stick is displayed as just single device. So, it seems I should add some more argument to rule filter, but I can't find it out.
- Probably there's some better solution for device plug/unplug notifications? Please suggest if you know something.