From bd21fbe4ca4667b3a044a3c0ddccaceb04fdd279 Mon Sep 17 00:00:00 2001 From: Konstantin Koslowski Date: Fri, 10 Jan 2025 09:36:36 +0100 Subject: [PATCH] sway_volume: update toggle for more than 2 sinks --- bin/sway_volume | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bin/sway_volume b/bin/sway_volume index c1a4f1d..60e99fa 100755 --- a/bin/sway_volume +++ b/bin/sway_volume @@ -14,8 +14,8 @@ function _get_default_sink() { pactl info | grep "Default Sink" | cut -d ' ' -f 3 } -function _get_sink_nick() { - pactl -f json list sinks | jq -c ".[] | select(.name | contains(\"$1\")) | .properties.\"device.nick\"" | sed 's/"//g' +function _get_sink_desc() { + pactl -f json list sinks | jq -c ".[] | select(.name | contains(\"$1\")) | .description" | sed 's/"//g' } function notify() { @@ -24,7 +24,7 @@ function notify() { SOURCE_VOLUME=$(pactl list sources | grep "Name: $SOURCE" -A 8 | grep -oE '[0-9]*%' | head -n 1 | sed 's/%//') MUTE=$(pactl list sinks | grep "Name: $SINK" -A 8 | grep 'Mute:' | cut -d " " -f 2) SOURCE_MUTE=$(pactl list sources | grep "Name: $SOURCE" -A 8 | grep 'Mute:' | cut -d " " -f 2) - NICK=$(_get_sink_nick $SINK) + DESC=$(_get_sink_desc $SINK) ICON=$ICON_PATH/audio-volume-high.svg SINK_ICON="" @@ -43,11 +43,12 @@ function notify() { fi TITLE="${SINK_ICON} ${SINK_VOLUME}% / ${SOURCE_ICON} ${SOURCE_VOLUME}%" # $NOTIFY_APP -i $ICON -a "Volume" "$TEXT" - $NOTIFY_APP -i $ICON "$TITLE" "$NICK\n$(getProgressString 10 "$VOL1" "$VOL2" $SINK_VOLUME)" + $NOTIFY_APP -i $ICON "$TITLE" "$DESC\n$(getProgressString 10 "$VOL1" "$VOL2" $SINK_VOLUME)" } function _toggle_sink() { - sink_next=$(pactl list sinks | grep node\.name | grep -oE '"[a-zA-Z0-9_.-]*"' | grep -v $1 | sed 's/"//g' | sort -R) + sink_next=$(pactl list sinks | grep node\.name | grep -oE '"[a-zA-Z0-9_.-]*"' | grep -v $1 | sed 's/"//g' | sort -R | head -n 1) + echo "$sink_next" pactl set-default-sink $sink_next }