From c2fa015bee5b98f0d969e7621f7fcd75836062f6 Mon Sep 17 00:00:00 2001 From: amolinae06 Date: Mon, 21 Apr 2025 01:03:24 -0600 Subject: [PATCH] updated bluetooth script --- .local/bin/bluetooth | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/.local/bin/bluetooth b/.local/bin/bluetooth index 239964a..5c4564e 100755 --- a/.local/bin/bluetooth +++ b/.local/bin/bluetooth @@ -23,32 +23,25 @@ switchstate() { esac } -checkstate() { - if [ "$(bluetoothctl show | grep "Powered: yes")" ]; then - echo "󰂯 ON" - else - echo "󰂲 OFF" +scandevices() { + bluetoothctl --timeout 5 scan on + devices=$(bluetoothctl devices | awk '{$1=$2=""; print substr($0,3)}') + if [ -z "$devices" ]; then + notify-send "Bluetooth" "Error: No devices were found" + exit 1 fi -} -switchstate() { - case "$(checkstate | fuzzel -d)" in - "󰂯 ON") - bluetoothctl power off - notify-send "Bluetooth" "Bluetooth is disabled" - ;; - "󰂲 OFF") - echo "Bluetooth is enabled" - bluetoothctl power on - notify-send "Bluetooth" "Bluetooth is enabled" - ;; - *) exit ;; - esac + selection="$(printf "%s\n" "$devices" | fuzzel -d -p "Available devices: ")" + if [ -n "$selection" ]; then + mac=$(bluetoothctl devices | grep "$selection" | awk '{print $2}') + bluetoothctl connect "$mac" + notify-send "Bluetooth" "Connecting to $selection" + fi } case $(printf "%s\n" "󰂯 Connect Device" "󰂳 Change State" | fuzzel -d) in "󰂯 Connect Device") - echo menu ;; + scandevices ;; "󰂳 Change State") switchstate ;; *) exit ;; -esac +esac \ No newline at end of file