Created
February 9, 2023 13:24
-
-
Save onesixromcom/4928c71afe0fadbec07ef893a1027000 to your computer and use it in GitHub Desktop.
Repair/Reconnect bluetooth headset and set a2dp profile
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/sh | |
sudo rfkill block bluetooth | |
sudo rfkill unblock bluetooth | |
sudo systemctl restart bluetooth | |
# Change MAC address to fit your device. | |
DEVICE_MAC='12:12:12:12:12:12' | |
CARD_ID=$(pactl list short cards | grep "module-bluez5-device.c" | awk '{ print $1 }') | |
# Should check here if card is available. | |
pactl set-card-profile $CARD_ID off | |
bluetoothctl disconnect $DEVICE_MAC | |
bluetoothctl remove $DEVICE_MAC | |
bluetoothctl power off | |
#systemctl stop bluetooth | |
#sleep 5 | |
#systemctl enable bluetooth | |
#sleep 5 | |
sudo systemctl restart bluetooth rtkit-daemon.service | |
sleep 5 | |
bluetoothctl power on | |
bluetoothctl pairable on | |
bluetoothctl agent on | |
bluetoothctl default-agent | |
timeout 6s bluetoothctl scan on | |
# Here is error when turn off scaning. | |
bluetoothctl scan off | |
bluetoothctl pair $DEVICE_MAC | |
bluetoothctl trust $DEVICE_MAC | |
bluetoothctl connect $DEVICE_MAC | |
# Wait before card will be available. | |
CARD_ID="" | |
while [ -z "$CARD_ID" ] | |
do | |
CARD_ID=$(pactl list short cards | grep "module-bluez5-device.c" | awk '{ print $1 }') | |
done | |
echo "Current card id="$CARD_ID | |
echo "Setting AAC profile." | |
#pactl set-card-profile $CARD_ID a2dp_sink | |
#pactl set-card-profile $CARD_ID a2dp_sink_aac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment