There have been multiple accounts created with the sole purpose of posting advertisement posts or replies containing unsolicited advertising.

Accounts which solely post advertisements, or persistently post them may be terminated.

Help with sink switching script

I use the following oneliner to switch sinks:

wpctl set-default $(pw-cli i $(pactl list short sinks | awk ‘{print $2}’ | sd ‘easyeffects_sinkn’ ‘’ | 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: Kw+’) && 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:


<span style="color:#323232;">RET=$(pactl list sinks | rg Description: | sd '	Description: ' '') | tofi
</span><span style="color:#323232;">case $RET in
</span><span style="color:#323232;">	pactl list sinks | rg Description: | sd '	Description: ' '') pactl list short sinks | awk '{print $2}'
</span><span style="color:#323232;">esac
</span>

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: Kw+’) && 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 ,

Like this?


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

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 OP , (edited )
@Communist@lemmy.ml avatar

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.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • [email protected]
  • random
  • lifeLocal
  • goranko
  • All magazines