#!/usr/bin/env bash set -euo pipefail SIG=8 get_waybar_pid() { pgrep -u "$USER" -x waybar | head -n1 || true; } log() { echo "[waybar-audio-bridge] $*" >&2; } WAYBAR_PID="" while [[ -z "$WAYBAR_PID" ]]; do WAYBAR_PID="$(get_waybar_pid)" sleep 1 done log "connected to Waybar PID $WAYBAR_PID" # read pw-mon output, but only care about Audio nodes pw-mon 2>/dev/null | grep --line-buffered -E "Audio|Sink|Source|Stream|Node" | while read -r _; do # small debounce to avoid spamming CPU when multiple updates arrive fast sleep 0.2 if ! kill -0 "$WAYBAR_PID" 2>/dev/null; then WAYBAR_PID="$(get_waybar_pid)" [[ -z "$WAYBAR_PID" ]] && continue log "reconnected to Waybar PID $WAYBAR_PID" fi kill -RTMIN+"$SIG" "$WAYBAR_PID" 2>/dev/null || true done