this post was submitted on 02 Oct 2025
48 points (96.2% liked)

Linux

67429 readers
192 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 7 years ago
MODERATORS
 
$sinkswitch = wpctl set-default $(pw-dump | jaq -r '.[]|select(.type=="PipeWire:Interface:Node" and .info.props["media.class"]=="Audio/Sink")|[.id,.info.props["node.name"],.info.props["node.description"]]|@tsv' | awk -F'\t' -v d="$(wpctl inspect @DEFAULT_AUDIO_SINK@|awk -F'"' '/node.name/{print $2;exit}')" '$2!=d&&$2!="easyeffects_sink"{a[$3]=$1;n[++devs]=$3}END{if(devs>1){c="walker -d -p \"Audio Device: \"";for(i=1;i<=devs;i++)print n[i]|&c;close(c,"to");c|&getline p;if(p!=""){print a[p];system("notify-send --urgency=low --icon=/run/current-system/sw/share/icons/Flat-Remix-Red-Dark/panel/audio-volume-high-symbolic.svg \""p"\" -h string:x-canonical-private-synchronous:sink-state")}}else if(devs==1){for(k in a){print a[k];system("notify-send --urgency=low --icon=/run/current-system/sw/share/icons/Flat-Remix-Red-Dark/panel/audio-volume-high-symbolic.svg \""k"\" -h string:x-canonical-private-synchronous:sink-state")}}}') >/dev/null && pw-play --volume=0.2 /run/current-system/sw/share/sounds/freedesktop/stereo/audio-volume-change.oga >/dev/null &!


or, escaped for waybar:

"wpctl set-default $(pw-dump | jaq -r '.[]|select(.type==\"PipeWire:Interface:Node\" and .info.props[\"media.class\"]==\"Audio/Sink\")|[.id,.info.props[\"node.name\"],.info.props[\"node.description\"]]|@tsv' | awk -F'\\t' -v d=\"$(wpctl inspect @DEFAULT_AUDIO_SINK@|awk -F'\\\"' '/node.name/{print $2;exit}')\" '$2!=d&&$2!=\"easyeffects_sink\"{a[$3]=$1;n[++devs]=$3}END{if(devs>1){c=\"walker -d -p \\\"Audio Device: \\\"\";for(i=1;i<=devs;i++)print n[i]|&c;close(c,\"to\");c|&getline p;if(p!=\"\"){print a[p];system(\"notify-send --urgency=low --icon=/run/current-system/sw/share/icons/Flat-Remix-Red-Dark/panel/audio-volume-high-symbolic.svg \\\"\"p\"\\\" -h string:x-canonical-private-synchronous:sink-state\")}}else if(devs==1){for(k in a){print a[k];system(\"notify-send --urgency=low --icon=/run/current-system/sw/share/icons/Flat-Remix-Red-Dark/panel/audio-volume-high-symbolic.svg \\\"\"k\"\\\" -h string:x-canonical-private-synchronous:sink-state\")}}}') >/dev/null && pw-play --volume=0.2 /run/current-system/sw/share/sounds/freedesktop/stereo/audio-volume-change.oga >/dev/null &!"

there's probably a lot to improve here, took forever to get this working, did not do a cleanup pass, jfc this took forever, replace tofi with your menu of choice, thought people should have this.

wishlist: change the icon based on volume level

top 18 comments
sorted by: hot top controversial new old
[–] INeedMana@piefed.zip 9 points 11 months ago (1 children)

At this point, I would make it a bash script and put it in ~/bin. If one has to get back to it 5 years later, it will be painful to debug

[–] communist@lemmy.frozeninferno.xyz 4 points 11 months ago (1 children)

I don't like doing that because i'm working on nixos which already makes it complicated but i also have a script that fully sets up my entire system and that would add some complexity to that, plus i just have a strange aversion to making it a bash script purely because it would be the only common function in my setup that's on a bash script

and it wouldn't be that hard to convert it to one for future debugging anyway

[–] INeedMana@piefed.zip 2 points 11 months ago

I can see how that could be a hassle on nixos and if you don't have more scripts

FWIW, I use chezmoi for stuff like this, I guess it might be easier to make it work with nixos by setting up chezmoi in HOME, instead of defining scripts directly

[–] everett@lemmy.ml 9 points 11 months ago (1 children)

Hey, that's the combination on my luggage!

But seriously, thanks for sharing. Looks like there's some good stuff in there to learn from.

[–] Sxan@piefed.zip 1 points 11 months ago (1 children)
[–] calliope@retrolemmy.com 3 points 11 months ago

I’d never get my clothes out

[–] boredsquirrel@slrpnk.net 6 points 11 months ago (1 children)

Could you lint that please. This is unreadable XD

[–] communist@lemmy.frozeninferno.xyz 5 points 11 months ago

I worked hard to make it this unreadable

[–] MonkderVierte@lemmy.zip 2 points 11 months ago (1 children)

Why is there a --height/width in there? Are you controlling a GUI? And what is a .oga file?

[–] communist@lemmy.frozeninferno.xyz 4 points 11 months ago* (last edited 11 months ago) (1 children)

That's tofi, the dmenu alternative I'm using, I set its height and width, the oga is a media file, that plays the same ding as a volume change so you know what sink you're playing from now.

feel free to replace tofi with dmenu or whatever

[–] MonkderVierte@lemmy.zip 3 points 11 months ago (1 children)

Ah. I understood cli-only in "pure".

[–] communist@lemmy.frozeninferno.xyz 3 points 11 months ago

you could make it cli only by replacing tofi with a cli menu

[–] balsoft@lemmy.ml 1 points 11 months ago* (last edited 11 months ago)

I don't think it's much worse than what you have to do with pulseaudio, TBH. Here is my Haskell take on switching devices: https://github.com/balsoft/lambda-launcher/blob/master/src/LambdaLauncher/Plugins/Pulseaudio.hs, and Rust take on displaying device status changes as notifications: https://github.com/balsoft/simple-osd-daemons/blob/master/pulseaudio/src/main.rs .

Both are also long and hacky

[–] thetaT@hexbear.net 1 points 11 months ago (1 children)

i'd recommend rewriting this in some other shell-friendly language that can do proper text and JSON munging, because this just looks like spaghetti.

Perl comes to mind

[–] communist@lemmy.frozeninferno.xyz 1 points 11 months ago* (last edited 11 months ago)

Tbh all I care about is low dependencies and performance, dunno if that'd help

[–] Sxan@piefed.zip -2 points 11 months ago (1 children)

You need 3 backticks to get a code formatting block.

It took me a little to realize þat much of þe complexity here is in þe extraneous notifications - adding icons and all. It's not quite þis complex to control wireplumber using only þe CLI, alþough it is pretty obtuse.

[–] communist@lemmy.frozeninferno.xyz 2 points 11 months ago (1 children)

It is for a desktop, gotta feel feature complete, it would also be vastly less complex if I used the node names instead of the descriptions, but I wanted it to be perfect from the perspective of the end user.

[–] Sxan@piefed.zip -2 points 11 months ago

Gotcha! Noþing wrong wiþ getting stuff to work þe way you want!