After updating to 20.04 I found that the headphone jack does not work as it should. So as workaround I thought of running a script on an acpi event. eg when headphone jack is plugged-in to reload the sound module. This is the script:


#if [ -z "$1" ]; then
#  echo "Pulseaudio has these cards:"
#  pacmd list-cards | grep 'name: '

MODULE_INDEX=`pacmd list-modules | tac | grep -A 10 -e "argument: .*$1" | grep 'index:' | head -n 1 | cut -d ':' -f 2 | tr -d ' '`
MODULE_NAME=`pacmd list-modules | tac | grep -A 10 -e "argument: .*$1" | grep 'name:' | head -n 1 | cut -d ':' -f 2 | tr -d '<>'`
MODULE_ARGUMENTS=`pacmd list-modules | tac | grep -e "argument: .*$1" | head -n 1 | cut -d ':' -f 2 | tr -d '<>'`
#echo "Module index is $MODULE_INDEX"
#echo "Module name: $MODULE_NAME"
#echo "Module args: $MODULE_ARGUMENTS"

if [ -z "$MODULE_INDEX" ]; then echo "Could not find module index"; exit 0; fi
if [ -z "$MODULE_NAME" ]; then echo "Could not find module name"; exit 0; fi
if [ -z "$MODULE_ARGUMENTS" ]; then echo "Could not find module arguments"; exit 0; fi

#echo "Unloading module"
pacmd unload-module $MODULE_INDEX
#echo ""
#echo "Reloading module"
#echo ""

This works fine if I run it manually.

So next I want to run it on the acpi event. Using acpi_listen when I plug in the jack I get

jack/headphone HEADPHONE plug

Next in /etc/acpi/events I create file that contains

event=jack/headphone HEADPHONE plug

I restart acpid with

sudo service acpid restart

(I even restarted the system) But when I plugin the headphone jack nothing happens. Am I doing something wrong ?

Thanks in advance

  • Ensure your event filename consists only of letters, digits, and hyphen. Make sure your string, including whitespace, in the event line matches exactly what you saw.
    – meuh
    Apr 30, 2020 at 9:30
  • Thanks meuh for answering. To ensure I have no problem with spaces/typow I used acpi_listen > fix-sound and used that to make the event file. Is is not working. I don't know how to debug it. I can't find a acpi log anyware Apr 30, 2020 at 12:05
  • Hi, @user3292026, your .sh script must be executable: sudo chmod +x /etc/acpi/soundcard2.sh. Here is one similar question that could be worth: How do I disable the touchpad when the lid is twisted or closed?
    – pa4080
    Apr 30, 2020 at 14:05

1 Answer 1


I only have Ubuntu 18.04 so perhaps systemd has taken over control of more acpi events in 20.04 and you will need to find out how to disable that (e.g. in /etc/systemd/logind.conf). To get logging I added a line to /etc/default/acpid


and after sudo systemctl restart acpid I saw events in the systemd journal when plugging in the headphone, and it ran my script ok:

$ sudo journalctl -u acpid -f
... acpid[2554]: 9 rules loaded
... acpid[2554]: waiting for events: event logging is on
... acpid[2554]: received input layer event "jack/headphone HEADPHONE plug"
... acpid[2554]: rule from /etc/acpi/events/meuh matched
... acpid[2558]: executing action "/home/meuh/bin/myscript"
... acpid[2554]: action exited with status 0
... acpid[2554]: 1 total rule matched
... acpid[2554]: completed input layer event "jack/headphone HEADPHONE plug"
  • After enableing logging I see the same thing as you. The script seems to be executed but nothing happens I also get "action exited with status 0" but although the script seems to have run nothing happens. Still no sound. If I run the script manually it runs fine Apr 30, 2020 at 17:28
  • You could change your script to exit 1 when there is an error, rather than exit 0 as it does now. Also, you could get it to write to a file by putting exec >/tmp/log 2>&1 after line 1. pulseaudio might be expecting to be running from a user login environment these days; systemd changed a lot of things in that area.
    – meuh
    Apr 30, 2020 at 17:35
  • 1
    So I figured it out. The problem was that acpid script should run as a regular user, So I modified the "action" section as follows action=/bin/su -c "/etc/acpi/soundcard2.sh alsa" - username. Reason is that as root pulseaudio is not running so It can not reload something it is not already running. Thanks very much meuh for your help Apr 30, 2020 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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