Skip to content

Instantly share code, notes, and snippets.

@venam
Last active March 29, 2024 02:37
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save venam/bd453b4fd673ff8abb9323e69f182045 to your computer and use it in GitHub Desktop.
Save venam/bd453b4fd673ff8abb9323e69f182045 to your computer and use it in GitHub Desktop.
Set PipeWire volume natively on the default sink
#! /bin/sh
# the metadata only contains the name of the default sink
default_sink_name=$(pw-metadata 0 'default.audio.sink' | grep 'value' | sed "s/.* value:'//;s/' type:.*$//;" | jq .name)
default_sink_id=$(pw-dump Node Device | jq '.[].info.props|select(."node.name" == '" $default_sink_name "') | ."object.id"')
current_volume=$(pw-cli enum-params "$default_sink_id" 'Props' | grep -A 2 'Spa:Pod:Object:Param:Props:channelVolumes' | awk '/Float / {gsub(/.*Float\s/," "); print $1^(1/3) }')
change="${1:-0.1}" # defaults to increment of 0.1
new_volume=$(echo "$current_volume $change" | awk '{printf "%f", $1 + $2}')
# we need to reconvert to cubic root
#new_volume_cube=$(echo "$new_volume" | awk '{ print $1^3 }')
echo "$new_volume"
pw-cli s "$default_sink_id" Props "{ mute: false, channelVolumes: [ $new_volume_cube , $new_volume_cube ] }"
# or use wpctl instead
# wpctl set-volume "$default_sink_id" "$new_volume"
@rileyrg
Copy link

rileyrg commented Nov 5, 2023

wpctl help, shows a +/- option but I cant figure it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment