From be61070d0cd1cbe1b25ef3cedd94dab40efd47c0 Mon Sep 17 00:00:00 2001 From: InigoGutierrez Date: Sat, 11 Jun 2022 13:03:34 +0200 Subject: Created bluetooth/btConnect.sh to manage bluetooth connections with dmenu. --- bluetooth/btConnect.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 bluetooth/btConnect.sh (limited to 'bluetooth') 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})" -- cgit v1.2.1