aboutsummaryrefslogtreecommitdiff
path: root/.config/waybar/scripts/bluetooth-battery.sh
diff options
context:
space:
mode:
Diffstat (limited to '.config/waybar/scripts/bluetooth-battery.sh')
-rwxr-xr-x.config/waybar/scripts/bluetooth-battery.sh17
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