I am trying to determine if an a2dp sink is connected to my system each time a connection happens on bluetooth. I am using these rules:

ACTION=="add", SUBSYSTEM=="bluetooth", RUN+="/bin/sh -c '/home/myuser/on-connect-bluetooth.sh'"
ACTION=="remove", SUBSYSTEM=="bluetooth", RUN+="/bin/sh -c '/home/myuser/on-connect-bluetooth.sh'"

I thought about using pactl but according to this answer it is accessible only by a user, which udev is not. DBUS was mentionned but it is not clear to me how it could be leverage through a simple shell and without delving deep into the kernel API...

Through the udev rule I know the devpath in /sys/devices/ but there seems to be little information in there.

How can I know if an a2dp sink is present upon bluetooth connect/disconnect event?

1 Answer 1


A possible solution, albeit imperfect because relying on a third party tool which then needs to be installed and maintained, is:

bluetoothctl info | grep 0000110d-0000-1000-8000-00805f9b34fb

0000110d-0000-1000-8000-00805f9b34fb is a2dp UID.

You must log in to answer this question.

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