diff options
Diffstat (limited to 'bluetooth/btConnect.sh')
-rwxr-xr-x | bluetooth/btConnect.sh | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/bluetooth/btConnect.sh b/bluetooth/btConnect.sh new file mode 100755 index 0000000..801fbf3 --- /dev/null +++ b/bluetooth/btConnect.sh @@ -0,0 +1,43 @@ +#!/bin/sh + +# btConnect.sh +# +# Selects an available device to connect to or disconnect from. + +title='btConnect.sh' + +if [ "$1" = '-d' ]; then + if ! bluetoothctl info | grep -Fq 'Connected: yes'; then + notify-send "$title" "Not connected to any device." + exit 4 + fi + bluetoothctl disconnect + exit 0 +fi + +if ! systemctl show bluetooth | grep -Fq 'StatusText=Running'; then + sudo systemctl start bluetooth || exit 1 + notify-send "$title" "Started bluetooth.service" +fi + +if bluetoothctl show | grep -Fq 'Powered: no'; then + bluetoothctl power on || exit 1 + notify-send "$title" "Bluetooth controller powered on." +fi + +lines=$(bluetoothctl paired-devices | wc -l) +selected=$(bluetoothctl paired-devices | dmenu -c -bw 3 -i -l $lines -p "💓") || exit 1 +mac=$(echo $selected | cut -d' ' -f2) +name=$(echo $selected | cut -d' ' -f3-) + +if bluetoothctl info $mac | grep -F 'Connected' | grep -Fq 'yes'; then + notify-send "$title" "Already connected to ${name}\n(${mac})" + exit 2 +fi + +if ! bluetoothctl connect $mac; then + notify-send "$title" "Unable to connect to ${name}\n(${mac})" + exit 3 +fi + +notify-send "$title" "Connected to ${name}\n(${mac})" |