Using Xubuntu 18.04, I have a headset that I connect, with its own microphone input. Every time I connect it, I then have to launch pavucontrol, click to the "Input Devices" tab, then select the "Headset Microphone" (instead of "Internal Microphone") in the "Port" drop down menu.

Whenever I disconnect the headset, the "Port" gets switched back to "Internal Microphone", so I have to repeat the process the next time I connect the headset.

Is there a way to do this automatically, or with minimal effort on my part?

I searched online and saw the advice to ensure the PulseAudio module-switch-on-connect is loaded, but I checked pactl list short modules and it appears to be already loaded.

2 Answers 2


I almost fix it on my laptop running Debian 10 this way:

  1. Unplug your headset.
  2. Edit /etc/pulse/daemon.conf — set log-level = debug
  3. Restart pulseaudio: pulseaudio -k
  4. Run journalctl --follow in a separate terminal/tmux window
  5. Plug in your headset and watch what happens. module-alsa-card.c: Jack 'Headphone Mic Jack' is now plugged in says which jack is detected
  6. Edit /usr/share/pulseaudio/alsa-mixer/paths/analog-input-headset-mic.conf, find the [Jack Headphone Mic] section and change state.plugged from unknown to yes

I said "almost", because

  1. Mic gain did not restore
  2. It does not distinguish external loudspeakers (TRS jack) and headset (TRRS jack) and switch input source anyway, so I get static noise instead of internal mic audio.

The blog post guided me this direction.

  • 1
    Worked, thanks! I just wish there was a way to restore the microphone gain as well...
    – Goh
    Commented Aug 22, 2020 at 0:52

The solution sent above works for some PCs, but not for all. I tested solutions for a long time that I could find in the documentation or on forums and this was the only one that worked.

So here is a script that I created that you can add when starting a session (unfortunately not for the entire computer because PulseAudio is a service that runs independently for each user).

index=$(pacmd list-sources | egrep 'index|ports|analog-input-headset-mic' | egrep '\*\sindex:\s+[0-9]'  | cut -d':' -f2);

acpi_listen | while IFS= read -r line;
    if [ "$line" = "jack/headphone HEADPHONE plug" ]
       pacmd set-source-port $index analog-input-headset-mic;
    elif [ "$line" = "jack/headphone HEADPHONE unplug" ]
       pacmd set-source-port $index analog-input-internal-mic;

This topic is part of my sources and here is another link that helped me in my research and to develop my script:

  • This worked for me in Kubuntu 21.04 and Realtek ALC3204 Commented Jun 9, 2021 at 17:25

You must log in to answer this question.

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