Is there a way of muting sound from my computer everytime I unplug my headphones (Like a phone does) to stop sound then playing out of my speakers?
Is there a way of muting sound from my computer everytime I unplug my headphones (Like a phone does) to stop sound then playing out of my speakers?
Howto detect an unplug
Basically what worked for me was:
For me the difference was in 'Node 0x16' under 'Amp-Out vals':
So I based the detection on the difference found.
Howto mute
With this knowledge you can have a script running in the background. If unplugged the scripts mutes your speakers like using
amixer sset Master playback 0%
(or any other command).You can make it executable with
chmod +x scriptname.sh
and put it in the startup applications. You will have to adjust the unplug detection though by finding your own difference in/proc/asound/card0/codec#0
(maybe even change the numbers here for multiple soundcards.Related Links:
https://wiki.ubuntu.com/Audio/PreciseJackDetectionTesting
https://unix.stackexchange.com/questions/25776/detecting-headphone-connection-disconnection-in-linux
How to automatically change volume level when un-/plugging headphones?
This worked for me on Ubuntu 14.04:
"with the headphones out mute it. Insert headphones and raise volume. Remove headphones and check for mute."
Credit: RevDrStrangelove on https://www.reddit.com/r/LifeProTips/comments/369k76/lpt_request_automaticly_mute_laptop_after_headset/
For ubuntu-16.10 I made few change in this answer.
If you have problems with events catching in
/etc/acpi/handler.sh
see my answer. It's also without device codes asNode 0x16
.