Skip to content

Instantly share code, notes, and snippets.

@jrh-spg
Last active December 22, 2019 18:50
Show Gist options
  • Save jrh-spg/c8be98c4f9bb01ecac894d676d2d00e4 to your computer and use it in GitHub Desktop.
Save jrh-spg/c8be98c4f9bb01ecac894d676d2d00e4 to your computer and use it in GitHub Desktop.
Pulse Audio Sink Selector
#!/bin/bash
tempfile=$(tempfile 2>/dev/null) || tempfile=/tmp/test$$
trap "rm -f $tempfile" 0 1 2 5 15
INPUT=$(mktemp)
function get_all_sinks() {
pacmd list-sinks | grep -e 'name:' | cut -d: -f2 | cut -d\< -f2 | cut -d\> -f1
}
function set_sink() {
pacmd set-default-sink ${choice}
}
availableSinks=$(get_all_sinks)
function sinkList() {
number=0
for sink in $(get_all_sinks); do
printf "%s " $((number++)) ${sink}
done
}
function menu() {
dialog --clear \
--backtitle "Select Pulse Audio Sink" \
--stdout \
--title "[ Sink Selector ]" \
--menu "Select Pulse Audio Sink" \
25 70 21 \
$(sinkList) >${tempfile}
}
$(menu)
retval=${?}
choice=$(cat ${tempfile})
case ${retval} in
0)
killall pulseaudio
dialog --clear \
--title "Sinkerator" \
--msgbox "Selected ${choice}" \
5 40
$(set_sink)
clear
;;
1)
dialog --clear \
--title "Sinkerator" \
--msgbox "Canceled!" 5 15 ;;
255)
dialog --clear \
--title "Sinkerator" \
--msgbox "ESC Pressed" 5 15 ;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment