4

I'm trying to look for a command that outputs 1 or 0 depending on whether I have my output muted.

I was trying this:

amixer sget Master

This is the output I get:

Simple mixer control 'Master',0
  Capabilities: pvolume pvolume-joined pswitch pswitch-joined
  Playback channels: Mono
  Limits: Playback 0 - 64
  Mono: Playback 64 [100%] [0.00dB] [on]

Now the values change here accordingly (if I decrease volume, the percentage and the dB values change). However, if I head into Pavucontrol and mute my output on the 'Output devices' tab, the output of the command above stays the same. Literally nothing changes. But my sound indeed is muted.

What command should I use? Why doesn't that [on] change to [off]? Shouldn't it?

Thanks in advance.

3 Answers 3

7

After a long search, I actually managed to find an answer. This might be helpful for others looking for something like this out there!

What you need:

pacmd list-sinks

This command has a line like this:

muted: no

And this no indeed does change to yes, when I mute my device. Perfect. I managed to strip the output using this command, should anyone need it:

pacmd list-sinks | awk '/muted/ { print $2 }'

Sorry for posting too soon, it seemed like I won't be able to find a solution anywhere.

1
  • 1
    What if you have multiple sinks? Similarly, if you do have multiple sources, the above code need more fine-tuning
    – SHW
    Commented Jan 14, 2021 at 16:15
6

Alternatively, for those like me who don't have PulseAudio or want to only use amixer, one solution is:

amixer get Master | sed 5q | grep -q '\[on\]'

returning 0 if unmuted and 1 if muted.

1
  • I used something similar and it doesn't rely on sed, amixer get Master | tail -2 | grep -c '\[on\]'. It returns 2 when muted. Commented Jan 23, 2021 at 2:34
2
pactl get-sink-mute @DEFAULT_SINK@

Outputs Mute: no if not muted, Mute: yes if muted.

Works even if you have multiple output. @DEFAULT_SINK@ is the symbolic name of, well the default output. From man pactl:

get-sink-mute SINK

Get the mute status of the specified sink (identified by its symbolic name or numerical index).

1

You must log in to answer this question.

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