I want to make my speakers and headphone jack automatically mute when I return from hibernation/suspend, or maybe mute right before I hibernate/suspend. Now I could write a script to do that, but I know there are many ways I could go about doing that, however is there a right way to write this script and where would be the right place to put it compared to a basic work around that does not get the the deep system level where this script should reside.
The directory
/etc/pm/sleep.d/
contains scripts that are run when the system is suspended, hibernated, resumed (ie, comes back from suspend) or thawed (comes back from hibernation).So, your script should be placed in this directory, to be called on these events. The first argument to the script (ie, in
$1
) will be the action that is being performed (ie, one ofsuspend
,hibernate
,resume
orthaw
). Your script can be run on the resume and thaw actions to mute the volumes accordingly. Take a look at some of the existing scripts there for examples. The documentation for these hook scripts is in thepm-action
manpage.As for the muting itself: I'd suggest using
alsactl
to save the 'state' of the muted configuration to a file (eg./var/lib/alsa/asound-muted.state
). When the script is run, it can invokealsactl
to restore from this saved state:Alternatively, you can use
amixer
to set the value of a specific volume control to zero:— however, the arguments to amixer will depend on your specific sound hardware configuration.