Created
May 26, 2019 14:54
-
-
Save e-orz/6ac40189cdbc1ea30cdea8cd1948e945 to your computer and use it in GitHub Desktop.
connect to mdr-1000x bluetooth audio headphone (A2DP profile, set default, move current streams to the new one)
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
bluetooth-connect-a2dp.sh | |
#!/usr/bin/expect -f | |
set timeout 2 | |
set prompt "#" | |
spawn "bluetoothctl" | |
set address [lindex $argv 0] | |
expect "Agent registered" | |
expect -re $prompt | |
send "connect $address\r" | |
expect { | |
"Connection successful" { send "quit\r"; exit 0 } | |
timeout { send_user "Couldn't connect\n"; send "quit\r"; exit 1 } | |
} | |
send_user "Unexpected happened\n" | |
send "quit\r" | |
exit 1 |
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 | |
DEV=$1 | |
PULSE_DEV="${DEV//:/_}" | |
bluetooth-connect-a2dp.sh $DEV | |
if [ $? -ne 0 ] | |
then | |
notify-send -u critical -i gtk-dialog-warning "Error Connecting to Blutooth audio $DEV" "Couldn't connect to the device" | |
exit 1 | |
fi | |
pactl set-card-profile bluez_card.$PULSE_DEV a2dp_sink | |
if [ $? -ne 0 ] | |
then | |
notify-send -u critical -i gtk-dialog-warning "Error Connecting to Blutooth audio $DEV" "Couldn't move the sink to A2DP profile" | |
exit 1 | |
fi | |
pactl set-default-sink bluez_sink.$PULSE_DEV.a2dp_sink | |
if [ $? -ne 0 ] | |
then | |
notify-send -u critical -i gtk-dialog-warning "Error Connecting to Blutooth audio $DEV" "Couldn't set the device to be the default" | |
exit 1 | |
fi | |
pactl list short sink-inputs | cut -f1 | while read streamId | |
do | |
pactl move-sink-input "$streamId" bluez_sink.$PULSE_DEV.a2dp_sink | |
if [ $? -ne 0 ] | |
then | |
notify-send -u critical -i gtk-dialog-warning "Error Connecting to Blutooth audio $DEV" "Couldn't move stream $streamId to the device" | |
exit 1 | |
fi | |
done |
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
#change the below MAC address to the actual one | |
bluetooth-connect-and-move-audio.sh 00:00:00:00:00:00 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment