Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 1 down vote accepted

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 of suspend, hibernate, resume or 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 pm-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 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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.