TIL from the wonderful ArchWiki that one can specify @DEFAULT_SINK@
as the sink number as follows:
pactl set-sink-mute @DEFAULT_SINK@ toggle
pactl set-sink-volume @DEFAULT_SINK@ +1%
This simplification means that the series of commands to determine the active sink are unnecessary. Not only that, but it works even when the default sink isn't active ("RUNNING"). WTF this isn't documented clearly in the man page is beyond me. It is documented in pactl --help
however. 🖕🏻 pulseaudio!
Unfortunately pulseaudio doesn't have a single master volume that applies to all outputs ("sinks"). You have to know the index or logical name of the active ("RUNNING") sink (note that > 1 might be running…).
To get the index of the active sink you can run: pactl list sinks short | grep RUNNING | awk ' { print $1 } '
Then you can use the index of the active sink to set volume or mute.
For example, here's how to toggle muting the active sink:
pactl set-sink-mute "$(pactl list sinks short | grep RUNNING | awk ' { print $1 } ')" toggle
This example increases the volume by 1%:
pactl set-sink-volume "$(pactl list sinks short | grep RUNNING | awk ' { print $1 } ')" +1%
Note: pulseaudio allows increasing the volume above 100%! I guess this could be helpful in some contexts.