Krolyxon
Commit 85941a2

Branches

Refs →

aurora.configwaybarscriptsbluetooth-battery.sh

17 lines · 583 B · Bourne Again Shell (bash)

1#!/usr/bin/env bash
2
3# Find the UPower device path for any connected headset/headphones
4DEVICE_PATH=$(upower -e | grep -E 'headset|headphone' | head -n 1)
5
6# If no headset device is found in UPower, exit silently so Waybar hides the module
7if [ -z "$DEVICE_PATH" ]; then
8 exit 0
9fi
10
11# Extract the percentage value (e.g., "90%")
12PERCENTAGE=$(upower -i "$DEVICE_PATH" | awk '/percentage:/ {print $2}')
13
14# Output JSON format for Waybar
15if [ -n "$PERCENTAGE" ]; then
16 printf '{"text": "%s", "tooltip": "Headset Battery: %s", "class": "connected"}\n' "$PERCENTAGE" "$PERCENTAGE"
17fi