Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.