Patch-Source: https://github.com/misterdanb/avizo/pull/45 --- a/volumectl +++ b/volumectl @@ -24,9 +24,9 @@ # -b Allow volume to go above 100% (boost). # -D Choose a different sink (output) or source (input) than # the default (see pamixer --list-sinks and --list-sources). -# -p Choose the currently playing sink instead of the default. -# In case of multiple playing sinks, it will choose the -# first playing sink as reported by 'pactl'. +# -p Choose the currently playing sink (or source) instead of +# the default. In case of multiple playing sinks/sources, +# it will choose the first one as reported by pactl/pamixer. # -g Increase/decrease using gamma correction (e.g. 2.2). # -m Control the source (mic) instead of sink (output). # -u Unmute when changing the volume (+|-|=). @@ -57,11 +57,19 @@ expr "$1" : '[0-9]\+$' >/dev/null } +playing_dev_id() { + if command -v pactl >/dev/null; then + pactl list short ${1}s | grep RUNNING | grep -m1 -o '^[0-9]\+' + else # this works since pamixer 1.6 + pamixer --list-${1}s | grep '"Running"' | grep -m1 -o '^[0-9]\+' + fi +} + all_flag=false dev= dev_type='sink' -use_playing= +use_playing=false opts= unmute_opt= optind=1 @@ -121,10 +129,8 @@ dev_opt='--default-source' elif [ "$dev" ]; then dev_opt="--$dev_type=$dev" -elif [ "$dev_type" = 'sink' ] && [ "$use_playing" ]; then - if dev=$(pactl list short sinks | grep RUNNING | cut -f 2 | head -n 1) && [ "$dev" ]; then - dev_opt="--$dev_type=$dev" - fi +elif $use_playing && id=$(playing_dev_id "$dev_type"); then + dev_opt="--$dev_type=$id" fi