What I want is the following:
- When I plug in my headphones, I want the sound to be un-muted and set to a specific volume level.
- When I unplug my headphones, I want the sound to be muted (or set to a specific volume level).
Setting the volume levels isn't the problem, but I somehow need to do this when un-/plugging the headphones, so I'm looking for a way to get notified of those events.
I quickly found
/proc/asound/card0/codec#0 to indicate whether headphones are plugged in or not, so I tried to monitor it using
inotifywait and change the volume level based on modified notifications. Unfortunately
inotifywait failed because proc isn't an ordinary filesystem.
Are there other ways to do this (maybe via PulseAudio)?
To summarize what I've tried so far:
- Ear Candy: didn't run at all on my system. Seems to be an abandoned project?
- The code posted by Karl Bielefeldt might work on some hardware, it doesn't on mine.
- The idea from StephenPaulger fails due to the lack of a 'Speaker' channel.
- Motivated by aking1012 I made it work by hacking around in the kernel code (after finding the jack sensing code of the codec), but that's a rather cumbersome solution.
So, I'm still looking for an easy way to do this.