I'm trying to run a script automatically right after a certain bluetooth device is connected. To do so, I tried to create a new UDEV rule. The problem I encounter is that my rule doesn't execute upon establishing the connection.

As of now, my rule contains only the MAC address of the device.

ACTION=="add", SUBSYSTEM=="bluetooth", ATTRS{address}=="a0:b1:c2:e3:f4:56", RUN+="/home/myhome/my_script"

How can I find more device details in order to add them to the rule?

When the device is connected, I can see the following UDEV event:

$ udevadm monitor
UDEV  [7704849.324977] add      /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.7/2-1.7:1.0/bluetooth/hci0/hci0:12 (bluetooth)

Is there any information in the above event that I can leverage?

I place the rule in both UDEV rules places, /etc/udev/rules.d/ and /lib/udev/rules.d/, but still it doesn't run. I'm on a Linux Mint system.

The rule has same permissions as all the other rules in the directory:

-rw-r--r-- 1 root root  369 Oct 17 13:07 50-my_bluetooth_rule.rules

I also played around with the rule number between 50 and 90. Still, no success.

  • Have you run udevadm control --reload-rules && udevadm trigger after creating that file? Oct 17, 2018 at 19:56
  • @IporSircer Yes I did. Nothing happens.
    – slybloty
    Oct 17, 2018 at 20:01
  • Your script should start with #!/bin/bash
    – GAD3R
    Oct 17, 2018 at 20:18
  • @GAD3R yes the script is as such. But the problem is the rule doesn't get run at all.
    – slybloty
    Oct 17, 2018 at 20:23

3 Answers 3


Use sudo tail -f /var/log/syslog to get the idVendor and the idProduct the write the udev rule to /etc/udev/rules.d/50-my_bluetooth_rule.rules as follows:

ACTION=="add" , SUBSYSTEM=="usb", ATTR{idVendor}=="xxx", ATTR{idProduct}=="yyy", RUN+="/home/myhome/my_script"


sudo service udev restart
sudo tail -f /var/log/syslog

Reconnect your bluetooth device. You can use logger in your bash script to write messages to syslog.

  • 1
    Your answer guided me to the root problem. It wasn't the inability to pick up the device when connected. The issue was that my script had to be run as my user not root in order to render the desired output.
    – slybloty
    Oct 18, 2018 at 19:57

In my case, the issue was that I had to use ATTRS{name} rather than ATTRS{address}. I found this out by issuing:

udevadm info -ap /devices/virtual/input/input160/event6

More info here.


I had a similar problem. I solved it by listening to dbus-monitor and running my script under a particular Bluetooth event. In particular,

dbus-monitor "interface='org.blueman.Applet',member='MenuChanged'"|
while read -r line; do

notify-send 'my bluetooth keyboard has just connected! High time to run my script'



You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .