Skip to content

Instantly share code, notes, and snippets.

@ayosec
Created June 16, 2020 17:10
Show Gist options
  • Save ayosec/b927c7a57d226453a7a16a20e9ffc1ce to your computer and use it in GitHub Desktop.
Save ayosec/b927c7a57d226453a7a16a20e9ffc1ce to your computer and use it in GitHub Desktop.
#!/bin/bash
MAC=01_23_45_67_89_AB
FILTER=$(paste -sd, <<FILTER
type='signal'
sender='org.bluez'
interface='org.freedesktop.DBus.Properties'
path='/org/bluez/hci0/dev_$MAC'
member='PropertiesChanged'
arg0='org.bluez.Device1'
FILTER
)
dbus-monitor --system "$FILTER" \
| sed -u '/^signal/ { :s N; /]/be; bs; :e s/\n//g }' \
| grep --line-buffered 'Connected.*true' \
| while read
do
dbus-send \
--system \
--print-reply \
--dest=org.bluez \
--type=method_call \
/org/bluez/hci0/dev_$MAC \
org.bluez.Device1.Connect
pactl set-card-profile "bluez_card.$MAC" "a2dp_sink"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment