Skip to content

Instantly share code, notes, and snippets.

@r0xsh
Created November 14, 2019 23:19
Show Gist options
  • Select an option

  • Save r0xsh/38a83a97e2ece98cb40b9c95d7826185 to your computer and use it in GitHub Desktop.

Select an option

Save r0xsh/38a83a97e2ece98cb40b9c95d7826185 to your computer and use it in GitHub Desktop.
Switch between pulseaudio sinks
get_sinks()
{
pacmd list-sinks |\
grep -E 'index:|device.description' |\
sed -e 's/^ *//;s/ *$//' -e 's/^\t*//;s/ *$//' -e 's/^* //'|\
sed -r -e 's/index: ([0-9]+)/[\1] /g' -e 's/device.description = "(.*)"/\1/g' |\
sed -ze 's/] \n/] /g'
}
switch_sink_default()
{
pacmd set-default-sink $1 || echo failed
}
switch_sink_applications()
{
pacmd list-sink-inputs |
awk '/index:/{print $2}' |
xargs -r -I{} pacmd move-sink-input {} $1 ||
echo failed
}
switch_sink()
{
switch_sink_default "$@"
switch_sink_applications "$@"
}
switch_gui()
{
sink=$(get_sinks | rofi -dmenu)
switch_sink $(echo $sink | sed -re 's/^\[([0-9]+)\]/\1/' | cut -d' ' -f1 );
}
switch_gui
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment