updated bluetooth script

This commit is contained in:
λmolinae 2025-04-21 01:03:24 -06:00
parent 1f949a8172
commit c2fa015bee

View file

@ -23,32 +23,25 @@ switchstate() {
esac esac
} }
checkstate() { scandevices() {
if [ "$(bluetoothctl show | grep "Powered: yes")" ]; then bluetoothctl --timeout 5 scan on
echo "󰂯 ON" devices=$(bluetoothctl devices | awk '{$1=$2=""; print substr($0,3)}')
else if [ -z "$devices" ]; then
echo "󰂲 OFF" notify-send "Bluetooth" "Error: No devices were found"
exit 1
fi fi
}
switchstate() { selection="$(printf "%s\n" "$devices" | fuzzel -d -p "Available devices: ")"
case "$(checkstate | fuzzel -d)" in if [ -n "$selection" ]; then
"󰂯 ON") mac=$(bluetoothctl devices | grep "$selection" | awk '{print $2}')
bluetoothctl power off bluetoothctl connect "$mac"
notify-send "Bluetooth" "Bluetooth is disabled" notify-send "Bluetooth" "Connecting to $selection"
;; fi
"󰂲 OFF")
echo "Bluetooth is enabled"
bluetoothctl power on
notify-send "Bluetooth" "Bluetooth is enabled"
;;
*) exit ;;
esac
} }
case $(printf "%s\n" "󰂯 Connect Device" "󰂳 Change State" | fuzzel -d) in case $(printf "%s\n" "󰂯 Connect Device" "󰂳 Change State" | fuzzel -d) in
"󰂯 Connect Device") "󰂯 Connect Device")
echo menu ;; scandevices ;;
"󰂳 Change State") switchstate ;; "󰂳 Change State") switchstate ;;
*) exit ;; *) exit ;;
esac esac