From 8835b90bc30c4b2e57edb057f03076b890ab686c Mon Sep 17 00:00:00 2001 From: Riyyi Date: Tue, 14 Sep 2021 14:08:26 +0200 Subject: [PATCH] Scripts: Add output device selection to PulseAudio TCP module --- .local/bin/volctl | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.local/bin/volctl b/.local/bin/volctl index 4462989..4a7c703 100755 --- a/.local/bin/volctl +++ b/.local/bin/volctl @@ -43,7 +43,7 @@ ${B}COMMANDS${N} ${B}u${N}, ${B}unmute${N} Unmute volume. - ${B}p${N} <${U}STATE${N}>, ${B}pulsetcp${N} <${U}STATE${N}> + ${B}p${N} <${U}STATE${N}> <${U}DEVICE${N}>, ${B}pulsetcp${N} <${U}STATE${N}> <${U}DEVICE${N}> Set PulseAudio TCP module, possible values: on/off, 1/0, default enable. ${B}getv${N}, ${B}getvolume${N} @@ -76,7 +76,7 @@ done pulseTcp() { - if test "$1" = "off" || test "$1" = "0"; then + if test "$2" = "off" || test "$2" = "0"; then if pactl list modules short | grep -q module-simple-protocol-tcp; then pactl unload-module module-simple-protocol-tcp fi @@ -85,7 +85,16 @@ pulseTcp() "$0" p off - device="$(pactl list sources short | head -n 1)" + # Select audio output device + devices="$(pactl list sources short | awk '/alsa_output.*RUNNING/ { print }' | sort -k 2)" + select="$3" + if [ -z "$select" ]; then + echo "$devices" | sed -nE '=;s/.*alsa_output\.(.*)\.monitor.*/\1/p;' | sed 'N;s/\n/) /' + printf "Enter device to stream: " + read -r select + fi + + device="$(echo "$devices" | sed -n "${select}p")" source="$(echo "$device" | awk '{ print $1; }')" format="$(echo "$device" | awk '{ print $4; }')" channels="$(echo "$device" | awk '{ print $5 + 0; }')" @@ -127,7 +136,7 @@ case "$1" in pamixer --unmute ;; p*) - pulseTcp "$2" + pulseTcp "$@" ;; getv*) pamixer --get-volume