Last active
May 28, 2024 13:27
-
-
Save tomjnixon/1348383 to your computer and use it in GitHub Desktop.
PulseAudio output switcher script
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 | |
# Script to switch all programs to a specific sink. Why this isn't easy, i | |
# don't know. | |
# This script takes a single argument, the sink name, index, or alias (defined | |
# below). | |
# To make this work, you will need to: | |
# - In /etc/pulse/default.pa: | |
# change "load-module module-stream-restore" | |
# to "load-module module-stream-restore restore_device=false" | |
# This makes all streams use the default device when they start, rather | |
# than the last device. | |
# - Set up the sink_names array below. | |
# PulseAudio sink names are usually rather obtuse, and the indices can | |
# change, so you can declare short names for sinks in the array below. | |
# | |
# The format is '[alias]=device_name'. The sink names can be found with: | |
# $ pacmd list-sinks | grep '^\s*name' | |
# , and are the monstrosities between the angle brackets. | |
declare -A sink_names=( | |
[headphones]=alsa_output.usb-Burr-Brown_from_TI_USB_Audio_DAC-00-DAC.analog-stereo | |
[speakers]=alsa_output.pci-0000_00_1b.0.analog-stereo | |
) | |
sink=${sink_names[$1]:-$1} | |
( | |
echo set-default-sink $sink | |
pacmd list-sink-inputs | | |
grep -E '^\s*index:' | | |
grep -oE '[0-9]+' | | |
while read input | |
do | |
echo move-sink-input $input $sink | |
done | |
) | pacmd > /dev/null |
thank you so much, exactly what i needed! i even bound it to ctrl-shift-/ and ctrl-shift-* and it's super convenient!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
appreciated!