#!/bin/bash # Ein einfaches Skript zur Steuerung von Bluetooth über wofi und bluetoothctl # Funktion zum Anzeigen des Menüs show_menu() { # Prüfen, ob Bluetooth eingeschaltet ist if /usr/bin/bluetoothctl show | grep -q "Powered: yes"; then power_status="On" power_option="󰟙 Turn Off" else power_status="Off" power_option="󰟘 Turn On" fi # Menüoptionen zusammenstellen options="$power_option\n󰂰 Scan for devices" # Liste der bekannten und gekoppelten Geräte abrufen devices=$(/usr/bin/bluetoothctl devices Paired | awk '{print $3, $4, $5, $6, $7}') if [ -n "$devices" ]; then options+="\n\nPaired Devices:" while read -r line; do mac=$(echo "$line" | awk '{print $1}') name=$(echo "$line" | cut -d' ' -f2-) if /usr/bin/bluetoothctl info "$mac" | grep -q "Connected: yes"; then options+="\n󰂱 $name (Connected)" else options+="\n󰂯 $name" fi done <<< "$devices" fi # Menü mit wofi anzeigen und Auswahl des Benutzers abrufen chosen=$(echo -e "$options" | wofi --dmenu --prompt "Bluetooth | Status: $power_status") # Auswahl verarbeiten case "$chosen" in "󰟙 Turn Off") /usr/bin/bluetoothctl power off ;; "󰟘 Turn On") /usr/bin/bluetoothctl power on ;; "󰂰 Scan for devices") # Scan im Hintergrund für 10 Sekunden in einem neuen Terminal starten alacritty -e bash -c "echo 'Scanning for 15 seconds...'; /usr/bin/bluetoothctl scan on; sleep 15; /usr/bin/bluetoothctl scan off; echo 'Scan finished.'; sleep 2" & ;; *) # Wenn ein Gerät ausgewählt wurde if [[ "$chosen" == *"Connected"* ]]; then mac=$(/usr/bin/bluetoothctl devices Paired | grep "$(echo "$chosen" | sed 's/ (Connected)//' | sed 's/󰂱 //')" | awk '{print $2}') /usr/bin/bluetoothctl disconnect "$mac" elif [[ "$chosen" == *"Paired Devices:"* ]] || [[ "$chosen" == "" ]]; then # Mache nichts, wenn der Header oder nichts ausgewählt wurde : else mac=$(/usr/bin/bluetoothctl devices Paired | grep "$(echo "$chosen" | sed 's/󰂯 //')" | awk '{print $2}') /usr/bin/bluetoothctl connect "$mac" fi ;; esac } show_menu