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
}
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