Skip to content

Instantly share code, notes, and snippets.

@ctsiaousis
Created June 3, 2021 20:44
Show Gist options
  • Save ctsiaousis/41bae98f442b01191684112bcfe184d8 to your computer and use it in GitHub Desktop.
Save ctsiaousis/41bae98f442b01191684112bcfe184d8 to your computer and use it in GitHub Desktop.
A UI for selecting and connecting to known bluetooth devices. Uses dmenu.
#!/bin/sh
MAC_ADDRESS="00:42:79:9D:01:7C"
customSpeaker() { #Automated sony speaker connection
echo -e "scan on\nconnect ${MAC_ADDRESS}\n" | bluetoothctl && sleep 7 &&
bluetoothctl info ${MAC_ADDRESS} | grep 'Paired: yes' &&
notify-send "MyBluetoothScript" "<i>connected to speaker</i>" &&
exit
}
#start the bluetooth service
sudo systemctl start bluetooth
# Get user choice for bluetooth connections:
chosen=$(printf "My Bluetooth Speaker\\nmanual" | dmenu -i -p "Select Bluetooth Device:") &&
case "$chosen" in
"My Bluetooth Speaker") customSpeaker ;;
"manual") urxvt -e sh -c "bluetoothctl" ;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment