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.
/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 of
thaw). 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 the
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 invoke
alsactl to restore from this saved state:
alsactl -f /var/lib/alsa/asound-muted.state restore <card-id>
Alternatively, you can use
amixer to set the value of a specific volume control to zero:
amixer -c 0 sset PCM,0 0
— however, the arguments to amixer will depend on your specific sound hardware configuration.