diff options
| author | krolyxon <me@krolyxon.com> | 2026-09-19 18:48:12 +0530 |
|---|---|---|
| committer | krolyxon <me@krolyxon.com> | 2026-09-19 18:48:12 +0530 |
| commit | ace9df58c7f7c4f5cf140f9bf17418c5947fcf5f (patch) | |
| tree | 9ad8c93fc386669265d3b34f00513ba10878a772 /.config/waybar/scripts | |
| parent | 35d4d854cbce40194ea34a16803ed5d46556a808 (diff) | |
waybar: add bluetooth battery status custom module
Diffstat (limited to '.config/waybar/scripts')
| -rwxr-xr-x | .config/waybar/scripts/bluetooth-battery.sh | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/.config/waybar/scripts/bluetooth-battery.sh b/.config/waybar/scripts/bluetooth-battery.sh new file mode 100755 index 0000000..392d980 --- /dev/null +++ b/.config/waybar/scripts/bluetooth-battery.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +# Find the UPower device path for any connected headset/headphones +DEVICE_PATH=$(upower -e | grep -E 'headset|headphone' | head -n 1) + +# If no headset device is found in UPower, exit silently so Waybar hides the module +if [ -z "$DEVICE_PATH" ]; then + exit 0 +fi + +# Extract the percentage value (e.g., "90%") +PERCENTAGE=$(upower -i "$DEVICE_PATH" | awk '/percentage:/ {print $2}') + +# Output JSON format for Waybar +if [ -n "$PERCENTAGE" ]; then + printf '{"text": "%s", "tooltip": "Headset Battery: %s", "class": "connected"}\n' "$PERCENTAGE" "$PERCENTAGE" +fi |
