Skip to content

Instantly share code, notes, and snippets.

@pcting
Last active September 1, 2022 16:44
Show Gist options
  • Save pcting/5c37c16261072fa60646d68767cc45c3 to your computer and use it in GitHub Desktop.
Save pcting/5c37c16261072fa60646d68767cc45c3 to your computer and use it in GitHub Desktop.
PulseAudio Bash Helpers
#!/bin/sh
pactl list sinks | grep --color=never -E '(^Sink|Name|device.description)' | sed 's/^Sink #//g' | sed -r 's/Name: //g' | sed -r '/[[:digit:]]$/{N;s/\n//}' | sed -r '/_sink$/{N;s/\n//}' | sed 's/\t\tdevice.description = /\t/g'
#!/bin/bash
CURRENT_DEFAULT_SINK=$(pactl get-default-sink)
# skip over displayport sinks
VIABLE_SINKS=$(pactl-compact-list-sinks | grep -v 'DisplayPort [[:digit:]] Output')
if [ -z "$VIABLE_SINKS=" ]
then
echo "No viable sinks found"
exit
fi
# find the next sink
NEXT_SINK=$(echo "$VIABLE_SINKS" | grep -A1 "$CURRENT_DEFAULT_SINK" | grep -v "$CURRENT_DEFAULT_SINK" | awk -F '\t' '{ print $2 }')
# if empty, wrap back to the 1st entry
if [ -z "$NEXT_SINK" ]
then
NEXT_SINK=$(echo "$VIABLE_SINKS" | head -n 1 | awk -F '\t' '{ print $2 }')
fi
set -x
pactl set-default-sink "$NEXT_SINK"
echo "Current Active Sink: $(pactl get-default-sink)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment