USB connect/disconnect notification

Questions about applications and software
Forum rules
Before you post please read how to get help
Post Reply
dimonomid
Level 1
Level 1
Posts: 18
Joined: Wed Feb 12, 2014 3:33 pm

USB connect/disconnect notification

Post by dimonomid »

Hi guys.

How can I set up notifications when I plug/unplug any USB device? In Windows we have at least sound notification, which is really useful.

I tried to install udev-notify , but it almost doesn't work on my Linux Mint 13 MATE: it works for very little time (1-2 minutes), and then, if I connect/disconnect any device, it crashes:

Code: Select all

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 other utilities I've found so far. How do you guys setup notifications of USB devices plug/unplug?

dimonomid
Level 1
Level 1
Posts: 18
Joined: Wed Feb 12, 2014 3:33 pm

Re: USB connect/disconnect notification

Post by dimonomid »

Well, I can't believe I'm the only one who needs this really useful feature. I wrote bash script and simple udev rules for that, if anyone wants, you can try it. Any feedback is appreciated.

Installation details

- Download this archive and unpack it somewhere. There's just one main script in it: my-udev-notify.sh, but archive also contains sounds for plug/unplug notifications, plus some more info, see readme.txt for details.
- Create file /etc/udev/rules.d/my-udev-notify.rules with the following contents: (don't forget to modify paths to your real path where you unpacked my-udev-notify.sh!)

Code: Select all

ACTION=="add",    RUN+="/bin/bash /path/to/my-udev-notify.sh -a add    -p '%p' -b '$attr{busnum}' -d '$attr{devnum}'"
ACTION=="remove", RUN+="/bin/bash /path/to/my-udev-notify.sh -a remove -p '%p' -b '$attr{busnum}' -d '$attr{devnum}'"
After this, it should work for newly attached devices. That is, if you unplug some device, you won't get notification. But when you plug it back, you will. (yes, for me it works without any udev restarting. If it doesn't for you, try rebooting)

To make it work for all devices, just reboot your system. NOTE that there might be many notifications during first boot (see known issues in the readme.txt). On second boot, there will be no notifications (unless you plug in new device when system is off)

You can customize it (turn on/off visual and sound notifications, or change sounds), check readme.txt in the archive for details.

User avatar
ElectroLund
Level 1
Level 1
Posts: 11
Joined: Tue Sep 26, 2017 12:19 pm
Location: Colorado
Contact:

Re: USB connect/disconnect notification

Post by ElectroLund »

Nice script! I'll have to give it a try when the http://hg.dfrank.ru server loads again.

I'm very surprised too that there's not some more hardware-centric debug tools like USB notification.

User avatar
Minterator
Level 5
Level 5
Posts: 596
Joined: Thu Jan 10, 2013 8:29 am

Re: USB connect/disconnect notification

Post by Minterator »

LM 13 had built-in notification sounds, and you can also change the sound files so that you get your favorite BADA-BING sound.

Many were deactivated in config, but notifications are built-in so no need to add udev rules.

I had added my own sound to notify when the laptop power charger was plugged in or removed.

Many find these sounds annoying, so they've been eliminated in subsequent versions.
Mint 17.3 MATE, kernel 4.11.12

User avatar
ElectroLund
Level 1
Level 1
Posts: 11
Joined: Tue Sep 26, 2017 12:19 pm
Location: Colorado
Contact:

Re: USB connect/disconnect notification

Post by ElectroLund »

Minterator wrote:LM 13 had built-in notification sounds, and you can also change the sound files so that you get your favorite BADA-BING sound.
Many were deactivated in config, but notifications are built-in so no need to add udev rules.
I had added my own sound to notify when the laptop power charger was plugged in or removed.
Can you elaborate to newbs like me on how/where you did your customization? I'm not seeing much in the System Settings panels. In the Sound \ Sounds Effects section, I do see a "Inserting Device" option, but it doesn't trigger when I insert a USB device.

Thanks!

User avatar
Minterator
Level 5
Level 5
Posts: 596
Joined: Thu Jan 10, 2013 8:29 am

Re: USB connect/disconnect notification

Post by Minterator »

ElectroLund wrote:
Minterator wrote:LM 13 had built-in notification sounds, and you can also change the sound files so that you get your favorite BADA-BING sound.
Many were deactivated in config, but notifications are built-in so no need to add udev rules.
I had added my own sound to notify when the laptop power charger was plugged in or removed.
Can you elaborate to newbs like me on how/where you did your customization? I'm not seeing much in the System Settings panels. In the Sound \ Sounds Effects section, I do see a "Inserting Device" option, but it doesn't trigger when I insert a USB device.

Thanks!

I don't have an LM13 installation handy. There's a config file and sound files under /usr/share/sounds For example, in /usr/share/sounds/freedesktop/stereo

power-plug.oga
power-unplug.oga

device-added.oga
device-removed.oga

etc.

I remember that I could change the sound to whatever. It didn't play windows .wav files so I had to convert using Audacity. It was a good way to waste time on long flights and annoy the other passengers with my BADA-BING sounds.
Mint 17.3 MATE, kernel 4.11.12

User avatar
bob466
Level 5
Level 5
Posts: 745
Joined: Mon May 15, 2017 5:23 am
Location: Australia

Re: USB connect/disconnect notification

Post by bob466 »

Mint 18.2 has a notification sound when a Flash Drive is plugged in...and when you click Eject and remove it...maybe you should update or go back to Windoze. :wink:
Linux For Ever...Windoze Never Image

Post Reply

Return to “Software & Applications”