Last active
May 21, 2024 18:21
-
-
Save venam/bd453b4fd673ff8abb9323e69f182045 to your computer and use it in GitHub Desktop.
Set PipeWire volume natively on the default sink
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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)..