From 8aaf45eb682eb56b8836d368536bccb95661fa9f Mon Sep 17 00:00:00 2001 From: noahpy Date: Fri, 19 Apr 2024 15:35:42 +0200 Subject: add disconnection from connected devices --- bluetooth-devices.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) mode change 100644 => 100755 bluetooth-devices.sh diff --git a/bluetooth-devices.sh b/bluetooth-devices.sh old mode 100644 new mode 100755 index ead8cae..e8a7517 --- a/bluetooth-devices.sh +++ b/bluetooth-devices.sh @@ -14,6 +14,18 @@ fi # Get MAC adress of the device you selected MAC=$(bluetoothctl devices | grep "$DEVICE" | sed 's/[^ ]* //' | cut -d ' ' -f1) +# If bluetooth device is already connected, disconnect +CONNECTED=$(bluetoothctl devices Connected | cut -f3 -d ' ') +if echo $CONNECTED | grep $DEVICE; then + if bluetoothctl disconnect $MAC | grep -q 'successful' + then + notify-send -t 5000 -r 2954 -u normal " Disconnected successfully from" " $DEVICE" + else + notify-send -t 5000 -r 2954 -u normal " Couldn't disconnect from" " $DEVICE" + fi + exit 0 +fi + # Send a notify whether the connection was successful if bluetoothctl connect $MAC | grep -q 'successful' then -- cgit 1.4.1