Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
6 edited tags
source | link

USB connect/disconnect notification Call notify-send from an udev rule

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-notifyudev-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 bugreportbugreport 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 /etc/udev/rules.d/notify.rules :

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:

device_plug.sh:

#!/bin/bash

export DISPLAY=":0"
notify-send "device plugged"

/usr/bin/play -q /path/to/plug_sound.wav &

device_unplug.sh:

#!/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:

  1. How to get actual title of the device attached, the same as I can see in lsusb output? 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)
  2. 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.
  3. Probably there's some better solution for device plug/unplug notifications? Please suggest if you know something.

Any help appreciated.

USB connect/disconnect notification

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 /etc/udev/rules.d/notify.rules :

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:

device_plug.sh:

#!/bin/bash

export DISPLAY=":0"
notify-send "device plugged"

/usr/bin/play -q /path/to/plug_sound.wav &

device_unplug.sh:

#!/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:

  1. How to get actual title of the device attached, the same as I can see in lsusb output? 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)
  2. 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.
  3. Probably there's some better solution for device plug/unplug notifications? Please suggest if you know something.

Any help appreciated.

Call notify-send from an udev rule

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 /etc/udev/rules.d/notify.rules :

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:

device_plug.sh:

#!/bin/bash

export DISPLAY=":0"
notify-send "device plugged"

/usr/bin/play -q /path/to/plug_sound.wav &

device_unplug.sh:

#!/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:

  1. How to get actual title of the device attached, the same as I can see in lsusb output? 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)
  2. 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.
  3. Probably there's some better solution for device plug/unplug notifications? Please suggest if you know something.
5 edited title
| link

udev rule: any device plug USB connect/unplug notificationsdisconnect notification

    Tweeted twitter.com/#!/StackUnix/status/437990174157709312
4 edited tags
| link
3 edited title
| link
2 deleted 1 characters in body
source | link
1
source | link