#!/bin/bash #---------------------------------------------------------------- # volctl — Volume control wrapper for PipeWire + WirePlumber # # Replaces the old ratflow volctl (PulseAudio-based). # Uses wpctl (WirePlumber CLI) for volume management. # # Usage: # volctl up — increase volume by 5% # volctl down — decrease volume by 5% # volctl toggle — toggle mute on default sink # volctl mute — mute default sink # volctl unmute — unmute default sink # # Environment: # SINK_NUM — if set, selects Nth sink (0=default, 1=next, etc.) # mirrors the old VOLCTL_SINK_NUM behavior # # Dependencies: wireplumber, wpctl, pipewire, pipewire-pulse #---------------------------------------------------------------- STEP=5 # Resolve which sink to use based on SINK_NUM (like old VOLCTL_SINK_NUM) # SINK_NUM=0 or unset → default sink, SINK_NUM=1 → second sink, etc. get_sink_id() { local num="${SINK_NUM:-0}" if [ "$num" = "0" ]; then echo "@DEFAULT_AUDIO_SINK@" else # List sinks and pick the Nth one (1-indexed in SINK_NUM) local sinks sinks=$(wpctl status | grep -A 100 'Audio' | grep -A 100 'Sinks:' | grep -oP '\d+\.' | head -n $((num + 1)) | tail -1 | tr -d '.') if [ -z "$sinks" ]; then echo "@DEFAULT_AUDIO_SINK@" else echo "$sinks" fi fi } SINK=$(get_sink_id) case "$1" in up) wpctl set-volume -l 1.5 "$SINK" "${STEP}%+" ;; down) wpctl set-volume "$SINK" "${STEP}%-" ;; toggle) wpctl set-mute "$SINK" toggle ;; mute) wpctl set-mute "$SINK" 1 ;; unmute) wpctl set-mute "$SINK" 0 ;; *) echo "Usage: volctl {up|down|toggle|mute|unmute}" echo " Set SINK_NUM env var to select sink (0=default, 1=second, etc.)" exit 1 ;; esac # Optional: send signal to waybar to update volume display # pkill -SIGRTMIN+1 waybar