Created
March 9, 2022 16:09
-
-
Save abdullahkhalids/21a51240c13e19bfbb6316f3dc77ddec to your computer and use it in GitHub Desktop.
A bash script that helps reliably connect to bluetooth headphones. Just bind the three possible inputs to different keyboard shortcuts.
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 | |
#sudo systemctl start bluetooth.service | |
connect() { | |
bluetoothstatus=`bluetooth | cut -c 13-` | |
if [ "$bluetoothstatus" == "off" ]; then | |
bluetooth on | |
sleep 2 | |
fi | |
connectstatus=`bluetoothctl info 98:52:3D:7E:5D:DE | grep Connected | cut -c 13-` | |
if [ "$connectstatus" == "no" ]; then | |
bluetoothctl connect 98:52:3D:7E:5D:DE | |
fi | |
echo "should be connected to Soundcore Liberty 2" | |
} | |
disconnect() { | |
bluetoothctl disconnect 98:52:3D:7E:5D:DE | |
bluetooth off | |
} | |
if [ "$1" == "general" ]; then | |
echo "general" | |
connect | |
pactl set-card-profile bluez_card.98_52_3D_7E_5D_DE a2dp-sink-sbc_xq | |
pactl set-default-sink bluez_output.98_52_3D_7E_5D_DE.a2dp-sink | |
pactl set-default-source alsa_input.pci-0000_00_1f.3.analog-stereo | |
fi | |
if [ "$1" == "headset" ]; then | |
echo "headset" | |
connect | |
pactl set-card-profile bluez_card.98_52_3D_7E_5D_DE headset-head-unit | |
pactl set-default-sink bluez_output.98_52_3D_7E_5D_DE.headset-head-unit | |
pactl set-default-source bluez_input.98_52_3D_7E_5D_DE.headset-head-unit | |
fi | |
if [ "$1" == "internal" ]; then | |
echo "internal" | |
disconnect | |
pactl set-default-sink alsa_output.pci-0000_00_1f.3.analog-stereo | |
pactl set-default-source alsa_input.pci-0000_00_1f.3.analog-stereo | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment