14

This seems so obvious I'm kind of shocked it needs to be asked. I plug a headset into the 3.5mm jack on my Ubuntu laptop and expect it to just work. The output does indeed "just work". However, I have to select the headset mic as default input, manually, every single time. How do I tell Ubuntu to behave like every other desktop/laptop OS, when a headset is plugged in?

Edit: upgrade to latest version of gnome gives a dialog asking what's been plugged in, each time I plug in the headset. However, selecting "headset" still results in the input device unchanged.

Edit #2: To be clear and to echo my comment below, the dialog is totally fine, if it works, which it doesn't.

3 Answers3

11

Why it doesn't work

My system, Kubuntu 19.10 on a Dell XPS 13 9350, detects headphones and sets the correct output automatically.

As fas as I know it doesn't know if the headset has a microphone or not. This is why it only changes the output and not the input.

How to make it work

This is how to automatically switch the microphone on plug/unplug:

acpi_listen is the tool to detect when you plug/unplug the headset. This is what it detects:

jack/headphone HEADPHONE unplug
jack/headphone HEADPHONE plug

pulseaudio is where we can switch source ports

In my system to select headset microphone:

pacmd set-source-port alsa_input.pci-0000_00_1f.3.analog-stereo analog-input-headset-mic

To select internal microphone:

pacmd set-source-port alsa_input.pci-0000_00_1f.3.analog-stereo analog-input-internal-mic

You can use pacmd list-cards to get a list of sources names and ports names.
You can also use the terminal auto-complete feature to help craft the commands.

Now, let's bring everything together:

Switch to root with sudo su and create the script /etc/acpi/headset-microphone.sh

#!/bin/sh
export PULSE_RUNTIME_PATH="/run/user/1000/pulse/"
if [ "$1" = plug ]; then
  sudo -u you -E pacmd set-source-port alsa_input.pci-0000_00_1f.3.analog-stereo analog-input-headset-mic
else
  sudo -u you -E pacmd set-source-port alsa_input.pci-0000_00_1f.3.analog-stereo analog-input-internal-mic
fi

be sure to:

  • change you to your username
  • replace the pulseaudio source and ports with your values
  • make the script executable, chmod a+x /etc/acpi/headset-microphone.sh

then create the event listener, creating a file ´/etc/acpi/events/headset-microphone-plug´:

event=jack/headphone HEADPHONE plug
action=/etc/acpi/headset-microphone.sh plug

and the unplug event listener, creating a file ´/etc/acpi/events/headset-microphone-unplug´:

event=jack/headphone HEADPHONE unplug
action=/etc/acpi/headset-microphone.sh unplug

and, as last thing, restart the acpi listening events service

systemctl restart acpid.service
1

After years, finally an gnome extension to save our lives. It removes the popup entirely, keeping the last selection.

https://extensions.gnome.org/extension/1482/remove-audio-device-selection-dialog/

0

Yet another GNOME Shell Extension: Auto select headset

This worked for me: https://extensions.gnome.org/extension/3928/auto-select-headset/

Description:

Auto selects headsets when possible instead of showing a dialog

Majal
  • 8,249