Created
September 19, 2022 12:33
-
-
Save thamudi/bdd99d51c779787b0b109fb94d106b6d to your computer and use it in GitHub Desktop.
Audio Devices switcher, switches by available audio sinks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script switches between multiple Pulseaudio output devices/sinks | |
# Created by Jan Keith Darunday [email protected] as the original script didn't work with pipewire | |
# This uses pactl instead of pacmd since pacmd is not available in pipewire | |
SINKS=$(pactl list short sinks) | |
SINK_COUNT=$(echo "$SINKS" | wc -l) | |
DEFAULT_SINK=$(pactl info | sed -En 's/Default Sink: (.*)/\1/p') | |
if [ "$DEFAULT_SINK" = "tunnel.serv.local.alsa_output.pci-0000_00_1b.0.analog-stereo" ]; then DEFAULT_SINK_INDEX=$(echo "$SINKS" | grep -n "$DEFAULT_SINK" | grep "tunnel" | egrep -o '^[0-9]+') | |
else DEFAULT_SINK_INDEX=$(echo "$SINKS" | grep -n "$DEFAULT_SINK" | grep -v "tunnel" | egrep -o '^[0-9]+')fiNEW_SINK_INDEX=$((DEFAULT_SINK_INDEX % $SINK_COUNT + 1))NEW_SINK=$(echo "$SINKS" | sed "${NEW_SINK_INDEX}q;d" | awk '{ print $2 }') | |
# Set next sink as the default sinkpactl set-default-sink "$NEW_SINK" | |
# Forward all playing audio (sink inputs) to the new sink | |
SINK_INPUTS=($(pactl list short sink-inputs | egrep -o '^[0-9]+')) | |
for SINK_INPUT in ${SINK_INPUTS[*]}; do pactl move-sink-input $SINK_INPUT $NEW_SINK; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment