# Muting audio with mixer.



## cardboardman (May 28, 2018)

How do I mute volume in FreeBSD laptop running 12-CURRENT? 

I tried running `mixer vol mute`, which sets the volume to 0. However there is no way to get back the old volume level, something line `mixer vol unmute` or even `mixer vol mute toggle`.

I run a minimal window setup around Xmonad, I came across the above issue because I wanted to bind the mute key XF86AudioMute, and couldn't find a simple option.


----------



## SirDice (May 28, 2018)

Topics about unsupported FreeBSD versions


----------



## Hakaba (May 30, 2020)

I have the same question in FreeBSD 12.1.

I search a way to toggle the sound, but toggle let the volume to 0:0 in the second call.

Here the behaviors:


```
mixer vol
> Mixer vol      is currently set to  50:50

mixer vol toggle
> Setting the mixer vol from 50:50 to 0:0.

mixer vol toggle
> Setting the mixer vol from 0:0 to 0:0.

man mixer | grep toggle
>           ^rec  toggles rdev of possible recording devices
```

How can we handle this ?
(I actually create a temp file with the volume value and delete it, but that sound very bad )


----------



## jmos (May 30, 2020)

Hakaba said:


> (I actually create a temp file with the volume value and delete it, but that sound very bad )


Why sounds that bad? You want to save something, a file is a perfect thing to do such things. It is the same as a any other configuration file.  And it's simple… Here's my example, can be saved f.e. as ~/bin/togglevol.sh:

```
#!/bin/sh

if [ -f ~/.togglevol ]
then
        mixer `cat ~/.togglevol`
        rm ~/.togglevol
else
        mixer -s vol > ~/.togglevol
        mixer vol 0:0
fi
```

I'm using entries in my start menu for mixer settings, but: I don't want to toggle, but want to return to my default settings. So there's one entry with my default listen settings, and one with my default settings for recordings.


----------



## Hakaba (May 30, 2020)

jmos said:


> Why sounds that bad?


If there is a toggle option, recreate the functionality sound bad.
But as you say, if there is no toggle option (and I did not see a toggle in man page) I will let the file do the job.
I have the same script (except file location is ~/.tmp/mixervol and I use && and || instead of if/then/else).
If we are two with the same needs, maybe we are a lot ?


----------



## aragats (May 30, 2020)

The easiest (IMO) solution I reported here back in 2018. Still perfectly working with x11/dzen2-based indicator in x11-wm/dwm.


----------



## Hakaba (May 31, 2020)

aragats said:


> The easiest (IMO) solution...


That sound easy. I adopt the solution. Thanks.

Here the result :
`mixer pcm | grep '0:0'; [ $? -eq 0 ]  && mixer pcm 100 ||  mixer pcm 0`


----------

