tao_pactl_setsink.sh (864B)
1 #!/bin/sh 2 3 # Set the output sink to an available device 4 # Requires pulse audio, uses the pactl interface 5 6 cmdf(){ command -v $1 >/dev/null 2>&1; } 7 ! cmdf "pactl" && \ 8 printf "Please install pactl to use me.\n" && exit 1 9 10 # dmenu command 11 if [ -z "$DMENU" ] 12 then 13 a="dmenu sxmo_dmenu.sh bemenu rofi" 14 for i in $a; do cmdf "$i" && export DMENU="$i" && break; done 15 fi 16 17 # optional configs 18 if [ -z "$DMENU_OPTS" ] 19 then 20 a="$HOME/.config/tao/tao_dmenu.conf" && [ -f "$a" ] && \ 21 DMENU_OPTS=$(<"$a" sed -n '1p' | tr -d "\n") 22 fi 23 24 a=$(pactl list sinks | \ 25 awk '{ 26 if (x==1){ 27 if (/^\tState: RUNNING/){ 28 state=">" 29 } 30 if (/^\tDescription/){ 31 sub(/^\tDescription: /,"") 32 print state, $0, sink 33 x=0 34 } 35 } 36 if (/^Sink/){ 37 x=1 38 sink=$2 39 state=" " 40 }}' | \ 41 "$DMENU" -i $DMENU_OPTS -p "[ audio sink select ]") 42 43 [ -n "$a" ] && \ 44 pactl set-default-sink ${a##* #}