Skip to content

Instantly share code, notes, and snippets.

@Sporif
Last active May 19, 2020 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sporif/f9033661b955d94765a1c4996023010c to your computer and use it in GitHub Desktop.
Save Sporif/f9033661b955d94765a1c4996023010c to your computer and use it in GitHub Desktop.
Set default pulseaudio sink
#!/usr/bin/env bash
# Set default pulseaudio sink and move all sink inputs there
# Requires
# load-module module-stream-restore restore_device=false
# in /etc/pulse/default.pa
[ -z "$1" ] && echo "You must specify a sink (either index or name):
$(pacmd list-sinks | grep index -A 1)" && exit 1
# New default sink
SINK="${1}"
# Driver to identify sink inputs to move
SINK_INPUT_DRIVER="protocol-native.c"
# Sink inputs to move
SINK_INPUTS="$(pacmd list-sink-inputs | grep "${SINK_INPUT_DRIVER}" -B 1 | awk '$1 == "index:" {print $2}')"
pacmd set-default-sink "${SINK}" && [ -n "${SINK_INPUTS}" ] && for i in ${SINK_INPUTS}; do
pacmd move-sink-input "${i}" "${SINK}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment