Created
January 5, 2014 11:21
-
-
Save emmaly/8267078 to your computer and use it in GitHub Desktop.
Bash script to automatically switch PulseAudio sink to Bluetooth headset on connect with A2DP profile and 50% volume.
This file contains 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 | |
sink_name="bluez_sink.00_42_1B_AD_FA_CE" | |
if [ -z "$1" ]; then | |
dbus-monitor --system "path=/org/bluez/777/hci0/dev_00_42_1B_AD_FA_CE, interface=org.bluez.AudioSink, member=Connected" | while read line; do | |
echo $line | |
$0 1 | |
done | |
else | |
if pacmd list-sinks | grep -qi $sink_name; then | |
if pactl stat | grep -qi $sink_name; then | |
echo "Already done." | |
else | |
echo "Setting profile..." | |
pactl set-card-profile bluez_card.00_42_1B_AD_FA_CE a2dp | |
echo "Setting sink..." | |
echo "set-default-sink $sink_name" | pacmd > /dev/null | |
echo "Setting volume..." | |
pactl -- set-sink-volume $sink_name 0 | |
pactl -- set-sink-volume $sink_name +50% | |
fi | |
else | |
echo "Not connected." | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's an alternative I wrote, which switches between the Bluetooth headset and my notebook's speakers.