From f789944f34b11f3ce0b0cb393b072cde90c27778 Mon Sep 17 00:00:00 2001 From: amolinae06 Date: Mon, 21 Apr 2025 20:37:17 -0600 Subject: [PATCH] bluetooth pair and discover --- .local/bin/bluetooth | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/.local/bin/bluetooth b/.local/bin/bluetooth index 5c4564e..6964d46 100755 --- a/.local/bin/bluetooth +++ b/.local/bin/bluetooth @@ -1,10 +1,11 @@ #!/bin/sh -x +# Created by λmolinae checkstate() { if [ "$(bluetoothctl show | grep "Powered: yes")" ]; then - echo "󰂯 ON" + echo "󰂯 Bluetooth ON" else - echo "󰂲 OFF" + echo "󰂲 Bluetooth OFF" fi } @@ -15,7 +16,6 @@ switchstate() { notify-send "Bluetooth" "Bluetooth is disabled" ;; "󰂲 OFF") - echo "Bluetooth is enabled" bluetoothctl power on notify-send "Bluetooth" "Bluetooth is enabled" ;; @@ -24,13 +24,16 @@ switchstate() { } scandevices() { + # https://github.com/bluez/bluez/issues/826 + notify-send "Bluetooth" "Scanning for devices" 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 - + + # TODO: Remove previously connected devices. selection="$(printf "%s\n" "$devices" | fuzzel -d -p "Available devices: ")" if [ -n "$selection" ]; then mac=$(bluetoothctl devices | grep "$selection" | awk '{print $2}') @@ -39,9 +42,30 @@ scandevices() { fi } -case $(printf "%s\n" "󰂯 Connect Device" "󰂳 Change State" | fuzzel -d) in - "󰂯 Connect Device") - scandevices ;; +toggledisc() { + if [ "$(bluetoothctl show | grep "Discoverable: yes")" ]; then + bluetoothctl discoverable off + notify-send "Bluetooth" "Discoverable off" + else + bluetoothctl discoverable on + notify-send "Bluetooth" "Set device as discoverable for 3 minutes" + fi +} + +togglepair() { + if [ "$(bluetoothctl show | grep "Pairable: yes")" ]; then + bluetoothctl pairable off + notify-send "Bluetooth" "Pairable off" + else + bluetoothctl pairable on + notify-send "Bluetooth" "Device is now pairable" + fi +} + +case $(printf "%s\n" "󰂯 Connect Device" "󰂱 Toggle discoverable" "󰂰 Toggle Pairable" "󰂳 Change State" | fuzzel -d) in + "󰂯 Connect Device") scandevices ;; + "󰂱 Toggle discoverable") toggledisc ;; + "󰂰 Toggle Pairable") togglepair ;; "󰂳 Change State") switchstate ;; *) exit ;; -esac \ No newline at end of file +esac