I'm currently trying to script the headphone plug-in/out event. I found out that I can script this quite easily as an acpi event..

I created a file in /etc/acpi/events/ with the event event=jack[ /]headphone, which then just calls my script.

I've also determined the file and exact line, which holds information about whether the headphones are currently plugged in or not. In the file /proc/asound/card0/codec#0 one specific Pin-ctls: is 0x00 if plugged in and 0x40: OUT if unplugged.

Now the problem I see there, is when I check the the current status of the headphone jack, as soon as the acpi event is triggered, will the codec#0 file already contain the current value? Might I have a race condition here? Or is it safe to use like that?

1 Answer 1


I found out that the problem can be easily circumvented, by checking for the specific plug/unplug event on the jack. The solution below will give the script the information about the specific jack events, which will mute sound, when the jack is unplugged.


event=jack[ /]headphone
action=/etc/acpi/actions/jack.sh "%e"



event=$(echo "$1" | cut -d " " -f 3)

case "$event" in
    amixer set Master mute

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .