Files
dotfiles/.local/bin/toggle_audio
2025-12-08 09:28:30 +00:00

33 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# Toggle default PipeWire sink between Built-in Audio and Cisco 700 USB Adapter
# Get sinks section
SINKS=$(wpctl status | sed -n '/Sinks:/,/Sources:/p')
# Extract IDs (ignore default * and Easy Effects virtual sinks)
BUILTIN_ID=$(echo "$SINKS" | tr -d '*' | grep -i "Built-in Audio" | grep -v "Easy Effects" | awk '{print $2}' | tr -d '.')
CISCO_ID=$(echo "$SINKS" | tr -d '*' | grep -i "Cisco HS 730-0TG" | 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" == *"alsa_output.pci-0000_00_1f.3.analog-stereo"* ]]; then
echo "Switching to Cisco HS 730-0TG..."
wpctl set-default "$CISCO_ID"
else
echo "Switching to Built-in Audio..."
wpctl set-default "$BUILTIN_ID"
fi
# Move active streams to new default sink
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"