about summary refs log tree commit diff stats
path: root/bluetooth-devices.sh
diff options
context:
space:
mode:
authornoahpy <noah.schlenker2002@gmail.com>2024-04-19 15:35:42 +0200
committernoahpy <noah.schlenker2002@gmail.com>2024-04-19 15:35:42 +0200
commit8aaf45eb682eb56b8836d368536bccb95661fa9f (patch)
tree9801ef964da1f4e72eaa91b7ece8c4b97dfc83dd /bluetooth-devices.sh
parent43b7f8d910851970bc7eb5fcb43289d7943da0ae (diff)
downloadbluetoothctl-dmenu-8aaf45eb682eb56b8836d368536bccb95661fa9f.tar.gz
bluetoothctl-dmenu-8aaf45eb682eb56b8836d368536bccb95661fa9f.zip
add disconnection from connected devices
Diffstat (limited to 'bluetooth-devices.sh')
-rwxr-xr-x[-rw-r--r--]bluetooth-devices.sh12
1 files changed, 12 insertions, 0 deletions
diff --git a/bluetooth-devices.sh b/bluetooth-devices.sh
index ead8cae..e8a7517 100644..100755
--- 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