Created
May 5, 2017 14:58
-
-
Save karlgrz/3666fe1cc4dc4572b72daeffbe66aaaa to your computer and use it in GitHub Desktop.
After all these years, finally scripted up something to help with bluetooth connect / disconnect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
mac_addr="XX:XX:XX:XX:XX:XX" # your bluetooth headset MAC address goes here, pactl list to get it | |
sink_addr="${mac_addr//\:/_}" | |
bluez_card="bluez_card.${sink_addr}" | |
bluez_sink="bluez_sink.${sink_addr}" | |
if bluetoothctl <<< "info $mac_addr" | grep -qi "Connected: no"; then | |
echo "connecting ${bluez_card}..." | |
bluetoothctl <<< "connect $mac_addr" | |
sleep 5s | |
pactl set-card-profile $bluez_card a2dp_sink | |
echo "set-default-sink ${bluez_sink}" | pacmd > /dev/null | |
pactl set-sink-volume ${bluez_sink} 0 | |
pactl set-sink-volume ${bluez_sink} +50% | |
else | |
echo "disconnecting ${bluez_card}..." | |
pactl set-card-profile $bluez_card off | |
sleep 5s | |
bluetoothctl <<< "disconnect $mac_addr" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment