Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Is there any command to check the PulseAudio sinks volume. Means I want display PulseAudio volume of particular sinks in %

i.e. 50%

I already set the volume using pactl set-sinks-volume 1 50% command. But now i want to check is it 50% or not.

So how can i do this?

share|improve this question

1 Answer 1

up vote 6 down vote accepted

You can use pactl list sinks to get info on the current state of your sinks. This returns a lot of information, including the volume. So, to get only the volume of sink 1, you can use:

pactl list sinks | perl -000ne 'if(/#1/){/(Volume:.*)/; print "$1\n"}'

This will return something like:

Volume: 0:  50% 1:  50%

The above perl command will print the details of sink 1. To use a different sink, change the #1 to another number, for example #0.

I am not sure what the two 50% mean, I assume they are the left and right speaker volumes. So, in order to check if they are above or below a specific value, (assuming that the balance is set to "center", that both left and right volumes are identical so only one needs to be checked), you can do:

pactl list sinks | perl -000lne 'if(/#1/){/Volume:.*?(\d+)%/; $1 >= 50 ? (print "y\n") : (print "n\n")}'

The above will print a y if the volume is greater than or equal to 50 and an n otherwise. This is all getting a bit complex though, so I would simplify by creating a script:

#!/usr/bin/env perl 

## The sink we are interested in should be given as the 
## 1st argument to the script.
die("Need a sink number as the first argument\n") if @ARGV < 1;
my $sink=$ARGV[0];

## If the script has been run with a second argument,
## that argument will be the volume threshold we are checking
my $volume_limit=$ARGV[1]||undef;

## Run the pactl command and save the output in 
## ther filehandle $fh
open(my $fh, '-|', 'pactl list sinks');

## Set the record separator to consecutive newlines (same as -000)
## this means we read the info for each sink as a single "line".

## Go through the pactl output
while (<$fh>) {
    ## If this is the sink we are interested in
    if (/#$sink/) {
        ## Extract the current colume of this sink
        my $volume=$1;
        ## If the script has been run with a second argument,
        ## check whether the volume is above or below that
        if ($volume_limit) {
            ## If the volume os greater than or equal to the
            ## value passed, print "y"
            if ($volume >= $volume_limit) {
               print "y\n";
                exit 0;
            else {
                print "n\n";
                exit 1;
        ## Else, if the script has been run with just one argument,
        ## print the current volume.
        else {
            print "$volume%\n";


Save the script above as in a directory in your $PATH (for example, /usr/local/bin), make it executable, chmod +x and then run it giving the sink you are interested as the first argument:

$ 1

To check whether the volume is above a given threshold, give the threshold as a second argument:

$ 1 50
$ 1 70

Note that this assumes your system language is English. If it isn't run the script with a changed locale:

LC_ALL=C 1 50
share|improve this answer
Thanks it's working great for me – Prakash V Holkar Apr 28 '14 at 9:00
How can I check the volume is >= 50% in if condition – Prakash V Holkar Apr 28 '14 at 9:31
@PrakashVHolkar see updated answer, I made a more complex script. – terdon Apr 28 '14 at 12:07
pactl outputs locale-dependent strings, causing commands in this answer to fail on non-english systems. Either prefix always with LC_ALL=C or type once export LC_ALL=C to set the shell (and all commands run from it) to the default locale. Then pactl | perl ... works. – Stéphane Gourichon May 21 at 9:49
@StéphaneGourichon good point, answer edited, thanks. – terdon May 21 at 12:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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