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.

  • You ask very politley :'D. All jokes aside, doing the following worked for me -- System Setting -> Sound -> Input Tab and selecting the input device of my choice. Which version of ubuntu are you running? – j-money Dec 05 '18 at 17:19
  • When a device is plugged into the 3.5mm jack, my Ubuntu (18.04) asks which kind of device I plugged in (either headset, headphones or microphone) and sets the input and output accordingly. This is done because I think there was no reliable way to detect whether a plugged-in device has input (mic), output (headphones) or both. If yours doesn't ask, it may be an Ubuntu flavor or an older version (though I'm pretty sure this behavior has been similar since 16.04 at least). – roadmr Dec 05 '18 at 17:26
  • @j-money I think I must have been annoyed when I wrote the question. :) I'm running 16.04 with gnome 3.18 (I believe). Following that procedure works for me as well, it is just annoying to have to do it each time I plug in the headset. – Dylan Roberts Dec 07 '18 at 15:04
  • @roadmr I'm using 16.04 with gnome 3.18. I don't get that dialog, but that would be totally acceptable! Going to see if I can figure out how to get that happening. :/ – Dylan Roberts Dec 07 '18 at 15:07
  • I don't remember if 16.04 had that behavior; you could download an 18.04 or 18.10 Live ISO image, put that in a USB stick, boot in "Try Ubuntu without installing" mode and check if it gives you the audio device prompt. If it does, you might consider upgrading. – roadmr Dec 21 '18 at 18:43
  • I too get this on Gnome 3 with Ubuntu 18, if I switch to KDE then I don't get it and also I don't get it with Gnome 3 on Fedora – icc97 Jan 21 '19 at 12:42
  • Possible duplicate: https://askubuntu.com/questions/775090/default-headphone-device-when-plugging-in-unknown-audio-device – icc97 Jan 21 '19 at 12:44
  • After doing an update to the latest version of gnome, still using ubuntu 16.04, I now get the dialog asking what I've plugged in (headset, headphones, mic); but no matter what I choose, it still doesn't change the selected input device! The term "useless" comes to mind. – Dylan Roberts Jan 22 '19 at 14:07
  • @icc97 I see this as a distinct question from that one that you've linked. That person is asking to disable the dialog in favour of a default option. I'd just like to know how to make the dialog selection actually take effect. – Dylan Roberts Jan 22 '19 at 14:08
  • Both want the system to correctly detect what was plugged in and not display the dialog – icc97 Jan 22 '19 at 14:29
  • @icc97 Nope. This one is fine with displaying the dialog, as long as it works, which it doesn't. – Dylan Roberts Jan 24 '19 at 22:35
  • The title of your question i.e. 'automatically' no longer matches your description. Using a dialog is selecting it manually. It seems like now your issue is just that it doesn't save the selection. As far as I can tell there is no simple solution. It's a bug somewhere near the hardware level which is hard to fix and probably won't have either a nice or an easy workaround. – icc97 Jan 25 '19 at 09:43
  • Did you figure it out? I also hate this behavior. – lonix May 31 '19 at 08:04

2 Answers2

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
  • Very nice! Ty his should be by implemented by default by the distribution creators. – dawez Jul 24 '20 at 09:14
  • script can be simplified by instead of passing 'plug' and 'unplug' to the script you instead pass 'internal' or 'headset' and inserting it into the appropriate sudo command. Though it could also be a 'security hole' unless you take care. – anthony Sep 18 '20 at 10:12
  • this can be useful to find right device https://unix.stackexchange.com/a/649206/194331 – Pawel Cioch Feb 24 '23 at 16:44
0

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/