6

I'm frequently changing the audio setup of my laptop (sometimes using the built-in jack port, sometimes nothing at all, sometimes using USB headphones, sometimes using the jack port in the dock of my laptop). I'd like to have keyboard shortcuts to lower or increase volume for all outputs at once, so it works no matter which audio output is currently active. What's the easiest way to achieve this? I also see that in pavucontrol, I can go above 100%, which is sometimes practical, so if the command was also able to do this, that'd be great.

I'm running Debian Testing, kernel 4.9.0-3-amd64, and pulseaudio 10.0.

Hauke Laging
  • 90,279
Ted
  • 313

1 Answers1

12

You need a script to do this. There are scripts like this that control the default sink, but I haven't seen one that controls all sinks.

You can get a list of all sinks with pacmd list-sinks, and set the volume with pacmd set-sink-volume, so you need to do something like

VOLUME='+5%'
for SINK in $(pacmd list-sinks | grep 'index:' | cut -b12-)
do
  pactl set-sink-volume $SINK $VOLUME
done

Where $VOLUME can be absolute (150%) or relative (+5%, -5%), and possibly other formats, too.

Most window managers can be configured to launch scripts or programs, complete with arguments, when you press keys. That's the best method, but if your WM doesn't, there are tools like xbindkeys. So you can customize in any way you want.

Note that Pulseaudio will start using hardware mixers if the sink volume goes over 100%, and that can distort the sound.

Also note that Pulseaudio allows to set the volume for each application ("audio stream") with pacmd set-sink-input-volume. You can list them with pacmd list-sink-inputs and set them similarly.

That allows you to have the sink volumes at a fixed level, so they are about equal, without using hardware mixers, and when you switch sinks, it will automatically have the "right" volume. That's the setup I prefer.

Pablo A
  • 2,712
dirkt
  • 32,309
  • 2
    Using percentages as $VOLUME returns "Failed to parse volume" errors. Changing the inner line to pactl set-sink-volume $SINK $VOLUME works. Thanks! =) – Ted Jun 29 '17 at 09:18
  • 1
    Right, now that you mention it I remember I ran into the same thing ... I've never understood why there are both pactl and pacmd. – dirkt Jun 29 '17 at 09:29
  • 1
    the complexity of these tools are insane. simple volume control shouldn't be this hard. Anyway, pacmd list-sinks | grep -B 4 RUNNING | grep index | awk ' { print $NF } ' also seems to work.

    The nice part of this approach is you're probably only using one audio output at once so you can dump the loop if you add a head -1 in there.

    – kristopolous Sep 22 '20 at 22:39