14

I can change the master volume with these commands (from the command line), and it affects all applications, but how do I change the volume for just one application (XMMS for example)?

amixer -q  set Master     toggle  # or pactl set-sink-mute   0 toggle
amixer -q sset Master 5%+ unmute  # or pactl set-sink-volume 0 -- -5%
amixer -q sset Master 5%- unmute  # or pactl set-sink-volume 0 -- +5%

pacmd dump # is interesting, and there are GUI applications that can do this: gnome-control-center sound, pavucontrol

1
22

You can get the number of sink Input with pactl command.

$ pactl list sink-inputs
...
Sink Input #7119
    Driver: protocol-native.c
    Owner Module: 12
    Client: 6298
    Sink: 0
...
Properties:
    application.icon_name = "google-chrome"
    media.name = "Playback"
    application.name = "Chromium"
...

Using this number(#7119), you specify the sink Input.

$ pactl set-sink-input-mute 7119 toggle

It will identify the application with application.icon_name property. The following is a case to specify the Chromium.

#!/bin/sh
LANGUAGE="en_US"

app_name="Chromium"

current_sink_num=''
sink_num_check=''
app_name_check=''

pactl list sink-inputs |while read line; do \
    sink_num_check=$(echo "$line" |sed -rn 's/^Sink Input #(.*)/\1/p')
    if [ "$sink_num_check" != "" ]; then
        current_sink_num="$sink_num_check"
    else
        app_name_check=$(echo "$line" \
            |sed -rn 's/application.name = "([^"]*)"/\1/p')
        if [ "$app_name_check" = "$app_name" ]; then
            echo "$current_sink_num" "$app_name_check"

            pactl set-sink-input-mute "$current_sink_num" toggle
        fi
    fi
done
2

For PulseAudio Roland Haas has written a tool:
https://github.com/rhaas80/pa_volume

I had to install libpulse-dev linux-libc-dev libc6-dev zlib1g-dev libpcre3-dev libglib2.0-0 libglib2.0-dev.
You might also need a compiler (gcc) to make.

Source: https://askubuntu.com/a/968540/382812 "How to change volume of pulseaudio playback-apps / -streams that aren't currently in use?"

5
  • 1
    This is possibly useful technical information that does not address the question at all.
    – Jeff Schaller
    Mar 25 '18 at 13:51
  • Why not? The question only says "maybe amixer or pactl".
    – äxl
    Mar 26 '18 at 14:46
  • It seems to me that this answer points to a link which points to a link to a tool that may answer the question. Perhaps you could make it more obvious to casual readers of this site what you're suggesting by incorporating the AU answer here (with a link back to AU). Otherwise, this answer currently looks like an attempt to solve a make/compilation error. Thank you!
    – Jeff Schaller
    Mar 26 '18 at 14:58
  • @JeffSchaller : I feel that it not only exactly addresses the problem, but also that the pa_volume utility it links to is indeed by far the best solution to this problem. And I have searched a long time...
    – mivk
    Aug 3 at 20:31
  • My point is that this question asks "how do I change the volume for just one application", and I don't see any steps in this Answer yet that demonstrate how to do that.
    – Jeff Schaller
    Aug 3 at 21:25
1

My snippet for playback volume control to change volume by 5% and toggle mute.

#!/bin/bash

inc() {
    playback_input=`pactl list sink-inputs short | awk '{print $1}' | head -1`
    pactl set-sink-input-volume $playback_input +5%
}

dec() {
    playback_input=`pactl list sink-inputs short | awk '{print $1}' | head -1`
    pactl set-sink-input-volume $playback_input -5%
}

mute() {
    playback_input=`pactl list sink-inputs short | awk '{print $1}' | head -1`
    pactl set-sink-input-mute $playback_input toggle
}
0

If you're looking for a TUI that does what pavucontrol does check out pulsemixer.

It does just that,

PulseMixer

You can see the Playback below, that shows all things playing to that sink (the sink-inputs).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.