Skip to content

Instantly share code, notes, and snippets.

@venam
Last active May 21, 2024 18:21
Show Gist options
  • 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.

@baudneo
Copy link

baudneo commented May 14, 2024

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

  • wpctl set-volume ID 5%- = 5% down (or 0.05-)
  • wpctl set-volume ID 5%+ = 5% up (or 0.05+)

@rieje
Copy link

rieje commented May 21, 2024

You can just do e.g. wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-. I came across this script because I'm looking for a way to get the active sink (AFAIK there's no such @ACTIVE_AUDIO_SINK@ alias)..

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