18

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

6 Answers 6

23

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
3

For PulseAudio, Roland Haas has written a tool.

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: 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, 2018 at 13:51
  • Why not? The question only says "maybe amixer or pactl".
    – äxl
    Mar 26, 2018 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, 2018 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, 2021 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, 2021 at 21:25
3

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
}
2

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).

2

When using PulseAudio, this function easily set the volume of any app.

function pacmd-set-app-volume() {
  local player="$1"
  local volume="$2"
  playerSinkIndex="$(pacmd list-sink-inputs | awk '/index:|application.name |application.process.binary / {print $0};' | grep -iC 1 "$player" | awk '/index:/ {print $2}')"  # get specific app sink
  [[ $playerSinkIndex ]] && pacmd set-sink-input-volume "$playerSinkIndex" "$((volume*65536/100))" # 100% → 65536
}

Could be added to .bashrc/.zshrc.

Usage:

pacmd-set-app-volume <loosly_app_name> <volume_percentage>  # For eg "MPV Media Player" 55 Or "mpv" "75"

Get name apps and binary with:

pacmd list-sink-inputs | awk '/index:|application.name |application.process.binary / {print $0};'
0

i used @pablo-a solution but edited it to work with pactl

#!/bin/bash
function pactl-set-app-volume() {
  local player="$1"
  local volume="$2"
  playerSinkIndex="$(pactl list sink-inputs |  awk '/application.name |object.serial / {print $0};' | grep -iA 1 "$player" | awk '/object.serial/ {print $3}' |  sed 's/"//g' )"  # get specific app sink
  [[ $playerSinkIndex ]] && pactl set-sink-input-volume $playerSinkIndex $volume
}
pactl-set-app-volume mpv 149%
sleep .5 #sleep to give the right effect
pactl-set-app-volume mpv +1%

this work for me very good

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .