I use the following oneliner to switch sinks:

wpctl set-default $(pw-cli i $(pactl list short sinks | awk '{print $2}' | sd 'easyeffects_sink\n' '' | sd "$(pactl get-default-sink)\n" '' | rg '.' || echo "$(pactl get-default-sink)" | tofi --prompt-text " " --height 40% --width 40% --auto-accept-single true ) | rg -oP 'id: \K\w+') && notify-send --urgency=low --icon=/usr/share/icons/Flat-Remix-Red-Dark/panel/audio-volume-high-symbolic.svg "$(pactl list sinks | rg -A 1 "Name: $(pactl get-default-sink)" | rg Description: | sd ' Description: ' '')" -h string:x-canonical-private-synchronous:sink-state && pw-play --volume=0.2 /usr/share/sounds/freedesktop/stereo/audio-volume-change.oga &!

This is great, however, i’d like it if the sink menu showed the descriptions for selection instead of the actual sink names

I’ve started a script like the following:

RET=$(pactl list sinks | rg Description: | sd '	Description: ' '') | tofi
case $RET in
	pactl list sinks | rg Description: | sd '	Description: ' '') pactl list short sinks | awk '{print $2}'
esac

but that doesn’t seem to work at all, any ideas for how to get this working?

edit: I found a better solution

$sinkswitch = wpctl set-default $(pw-cli i $(pactl list sinks | rg --fixed-strings -B 1 "$(pactl list sinks | rg Description: | sd ' Description: ' '' | sd 'Easy Effects Sink' '' | sd --fixed-strings "$(pactl list sinks | rg -A 1 "Name: $(pactl get-default-sink)" | rg Description: | sd ' Description: ' '')" '' | rg '.' || echo "$(pactl list sinks | rg -A 1 "Name: $(pactl get-default-sink)" | rg Description: | sd ' Description: ' '')" | tofi --prompt-text " " --height 40% --width 40% --auto-accept-single true )" | rg Name: | awk '{print $2}' ) | rg -oP 'id: \K\w+') && notify-send --urgency=low --icon=/usr/share/icons/Flat-Remix-Red-Dark/panel/audio-volume-high-symbolic.svg "$(pactl list sinks | rg -A 1 "Name: $(pactl get-default-sink)" | rg Description: | sd ' Description: ' '')" -h string:x-canonical-private-synchronous:sink-state && pw-play --volume=0.2 /usr/share/sounds/freedesktop/stereo/audio-volume-change.oga &!

  • gnuhaut@lemmy.ml
    link
    fedilink
    arrow-up
    2
    ·
    10 days ago

    Like this?

    #!/bin/sh
    set -eu
    
    name_from_desc() {
        LANG=C pactl list sinks \
            | awk 'BEGIN {FS=": "} /Name:/ {name=$2} /Description:/ {print name, ":", $2}' \
            | while IFS=' : ' read name desc; do
            if [ "$desc" = "$1" ]; then echo "$name"; fi
        done
    }
    
    id_from_name() {
        pw-cli i "$1" | awk '/id:/ {print $2}'
    }
    
    ret=$(LANG=C pactl list sinks | awk 'BEGIN {FS=": "} /Description:/ {print $2}' | tofi)
    
    wpctl set-default $(id_from_name $(name_from_desc "$ret"))
    

    I don’t get how that case statement of yours is even supposed to work. I’m pretty sure that’s just a syntax error. I guess you want to map from description to name? But that’s not remotely what that does.

    • Communist@lemmy.mlOP
      link
      fedilink
      English
      arrow-up
      2
      ·
      edit-2
      10 days ago

      I made a better solution in my post that works perfectly… and is better for me because it isn’t a script (I don’t like adding additional dotfiles) sorry for the unnecessary effort.