From cde6e39cec02175bc56f736f98dc017ac489481e Mon Sep 17 00:00:00 2001 From: Filip Rojek Date: Sun, 9 Nov 2025 13:53:01 +0100 Subject: [PATCH] added audio scripts used in my river configuration --- .local/bin/toggle_audio | 33 +++++++++++++++++++++++++++++++++ .local/bin/waybar_audio.sh | 25 +++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100755 .local/bin/toggle_audio create mode 100755 .local/bin/waybar_audio.sh diff --git a/.local/bin/toggle_audio b/.local/bin/toggle_audio new file mode 100755 index 0000000..26a4762 --- /dev/null +++ b/.local/bin/toggle_audio @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +# Toggle default PipeWire sink between Steinberg UR22mkII and Starship/Matisse + +# sinks +#STEINBERG_ID=60 +#STARSHIP_ID=59 +SINKS=$(wpctl status | sed -n '/Sinks:/,/Sources:/p') + +# Extract IDs (ignore default *) and match specific names +STARSHIP_ID=$(echo "$SINKS" | tr -d '*' | grep -i "Starship" | grep -v "Easy Effects" | awk '{print $2}' | tr -d '.') +STEINBERG_ID=$(echo "$SINKS" | tr -d '*' | grep -i "Steinberg" | grep -v "Easy Effects" | awk '{print $2}' | tr -d '.') + +# Get current default sink name (not just the ID) +CURRENT_SINK=$(wpctl status | awk '/Audio\/Sink/ {print $3}') + +# Detect which sink is active and toggle +if [[ "$CURRENT_SINK" == *"Steinberg"* ]]; then + echo "Switching to Starship/Matisse output..." + wpctl set-default "$STARSHIP_ID" +else + echo "Switching to Steinberg UR22mkII output..." + wpctl set-default "$STEINBERG_ID" +fi + +# Optionally move active streams +echo "Moving active streams to new sink..." +for stream in $(wpctl status | awk '/\. Stream/{print $1}'); do + wpctl move-stream "$stream" @DEFAULT_AUDIO_SINK@ 2>/dev/null +done + +# Confirm new default +echo "New default sink:" +wpctl status | grep "Audio/Sink" diff --git a/.local/bin/waybar_audio.sh b/.local/bin/waybar_audio.sh new file mode 100755 index 0000000..1f482a8 --- /dev/null +++ b/.local/bin/waybar_audio.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +# Get default sink name and volume +sink_info=$(pamixer --get-default-sink) +sink_name=$(echo "$sink_info" | awk '{print $3}') +volume=$(pamixer --get-volume) +muted=$(pamixer --get-mute) + +# Determine alt value for Waybar +if [ "$muted" = "true" ]; then + case "$sink_name" in + *Steinberg*) alt="headphones-muted" ;; + *) alt="speaker-muted" ;; + esac +else + case "$sink_name" in + *Steinberg*) alt="headphones" ;; + *) alt="speaker" ;; + esac +fi + +# Output JSON for Waybar +printf '{"text": "%s%%", "alt": "%s", "class": "%s", "percentage": %s }\n' \ + "$volume" "$alt" "$alt" "$volume" +