63

Including Natty I was always able to toggle (mute/unmute) the 'Master' sound volume with the

amixer sset Master toggle

command that I linked to an edge binding in CompizConfig-Manager.

Now after installing Oneiric the command only mutes the sound but doesn't unmute it. I even tried it in the Terminal but it also doesn't work. It changes 'Mono: Playback 68 [78%] [-14.25dB] [off]' to '...[on]' but the sound stays muted so that I have to unmute it via the 'sound-indicator' in the panel.

How can I get this working again? What did change since Natty? Does anyone know the command the 'sound-indicator' uses to toggle the sound volume?

1
  • And to make it even more strange: on my other laptop, where I upgraded from Natty to Oneiric instead of a fresh install, it still works.
    – joschi
    Oct 14, 2011 at 6:42

8 Answers 8

76

This works for me on 13.04, both mute and unmute:

amixer -D pulse set Master 1+ toggle

It specifies pulse audio to ensure unmute, unmutes everything.

6
  • 1
    EDIT: It only worked when running as a command in the terminal. But when i try to configure as a key binding I get: Home directory not accessible: Permission denied ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused amixer: Mixer attach pulse error: Connection refused Dec 10, 2013 at 1:44
  • 9
    It works even better without the 1+ parameter. Oct 13, 2014 at 2:05
  • 4
    Still works in 17.10 (artful). I'm using this for i3 media bindings: bindsym XF86AudioMute exec --no-startup-id amixer -D pulse set Master 1+ toggle
    – Joel
    Nov 15, 2017 at 20:25
  • 4
    What is the reason for 1+? Dec 24, 2017 at 10:30
  • 1
    @GayanWeerakutti After skimming man pages I'm unsure. This works fine without the 1+ for me: amixer set Master toggle
    – abelito
    Apr 27, 2021 at 15:08
20

I'm using this script as a workaround:

#!/bin/bash

CURRENT_STATE=`amixer get Master | egrep 'Playback.*?\[o' | egrep -o '\[o.+\]'`

if [[ $CURRENT_STATE == '[on]' ]]; then
    amixer set Master mute
else
    amixer set Master unmute
    amixer set Front unmute
    amixer set Headphone unmute
fi

I did a diff of amixer scontents before calling amixer set Master mute and after calling it and unmuting everything using the GUI to figure out what needed to be unmuted.


  1. With sound on type amixer scontents > ~/before (you'll get a file with the status of all sound chanels)
  2. Then toggle volume with amixer set Master toggle
  3. Create a second chanel status file with amixer scontents > ~/after
  4. Toggle sound again with amixer set Master toggle which is supposed to turn the volume back to the level before the first toggle command
  5. Create a third file with amixer scontents > ~/afterafter

Now you have three files telling you which tell you the status of the sound chanels used for normal sound, which are muted by amixer set Master toggle and which aren't turned on again by again unmuting with the same command.

To easily compare the files and see the differences (the chanels that get muted and won't unmute afterwards) you can use meld from the Software Centre. Start it, open the three files and on the scrollbar you can see where there are differences between the files. Use the found chanel names to add them to the above described script.

3
  • Unfortunately the script only mutes sound but doesn't unmute it
    – joschi
    Oct 24, 2011 at 17:35
  • That's probably because your things that need to be unmuted aren't called "Front" and "Headphone" like they are on my system. Oct 24, 2011 at 18:07
  • I also did a diff and found out what was missing for the script to work on my computer, now it works. Thanks a lot.
    – joschi
    Oct 24, 2011 at 20:11
6

I couldn't get sound muting to toggle correctly. Whether I used CLI and type in Amixer sset Master toggle or hit the HP pavillion media toggle key, I get the same result: If sound is on and working, it will automatically turn off Master channel AND PCM channel. Then when I hit the toggle again (cli or key) it ALWAYS turns on Master, but leaves PCM muted. For my rig (HP Pavilion DV6 running Xubuntu Oneric), this means sound is off even with master on. When run from CLI - same results. If, with cli, I toggle PCM, it also turns off master channel and again won't turn it back on, though it toggles PCM correctly.

The script that worked was:

#!/bin/bash
    if amixer -c 0 get Master | grep -q off
then
    amixer set Master unmute
    amixer set PCM unmute

else
    amixer set Master mute
fi

Then I used Xubuntu keybindings (settings> settings manager> keyboard> application shortcuts) to browse to the script (I called it sndfx.sh and set it to executable by right clicking in thunar and under permissions ticked make executable). Then I assigned the HP Pavilion quickkey to it by tapping that key. Now, it toggles correctly - Awesome. Hope this helps someone else.

Peace

3

If I'm not mistaken, it's a bug that causes other mixer channels to mute and unmute. To mute, try

amixer set Master 0;

To unmute try

amixer set Master 1%+; amixer set Master 7dB+;

2
  • These commands work, but they don't let me toggle the volume with a single command that I can combine with an edge binding.
    – joschi
    Oct 24, 2011 at 9:22
  • 1
    If anyone's interested in the associated bug report see here.
    – joschi
    Oct 24, 2011 at 9:28
1

If you want to replace amixer in .lircrc for your remotecontrol working with lirc, you can try following lines. Be sure to have xmacro installed. Volume-control now works again.

begin
        prog = irexec
        button = KEY_VOLUMEUP
        repeat = 1
        delay = 2
        config = echo KeyStrPress XF86AudioRaiseVolume KeyStrRelease XF86AudioRaiseVolume | xmacroplay $DISPLAY
end
begin
        prog = irexec
        button = KEY_VOLUMEDOWN
        repeat = 1
        delay = 2
        config = echo KeyStrPress XF86AudioLowerVolume KeyStrRelease XF86AudioLowerVolume | xmacroplay $DISPLAY
end
begin
        prog = irexec
        button = KEY_MUTE
        config = echo KeyStrPress XF86AudioMute KeyStrRelease XF86AudioMute | xmacroplay $DISPLAY
end
0

The trick is to make the speaker or headphone state follow the state of the master channel depending on if you have the headphones plugged in or not. This script does it for me on my ancient Dell Latitude laptop:

#!/bin/bash

amixer -q sset Master toggle

MASTER_STATE=`amixer get Master | awk -F"dB] " 'NR == 5 {print $2;}'`
HEADPHONES_PLUGGED=`amixer contents | grep -A 2 Headphone\ Jack | awk -F"=" 'NR == 3 {print $2;}'`

if [[ $HEADPHONES_PLUGGED == 'on' ]]; then
    SLAVE="Headphone"
else
    SLAVE="Speaker+LO"
fi

if [[ $MASTER_STATE == '[on]' ]]; then
    amixer -q sset $SLAVE unmute
else
    amixer -q sset $SLAVE mute
fi

You may need to check your channels with amixer on your computer and change the SLAVE definitions accordingly. Also the "Headphone\ Jack" grep string in the HEADPHONES_PLUGGED definition might need to be something else.

0

Incase anyone is looking for a different soloution. I used pactl commands.

To increase/decrease the volume use

pactl -- set-sink-volume 0 +10%

And to toggle mute use

pactl -- set-sink-mute 0 toggle

read more PACTL commands and usages set audio volume from the command line

-1

Brute force unmute:

for i in $(amixer |grep -o \'.*\'); do amixer set $i unmute; done
1
  • 2
    I don't think unmuting 80 and more devices is a good idea. This includes microphones, which can lead to unwanted feedback loops. do an for i in $(amixer |grep -o \'.*\'); do echo amixer set $i unmute; done before, to see what would be done. Apr 14, 2012 at 22:29

You must log in to answer this question.

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