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.

13
  • 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
    Commented Dec 5, 2018 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
    Commented Dec 5, 2018 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. Commented Dec 7, 2018 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. :/ Commented Dec 7, 2018 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
    Commented Dec 21, 2018 at 18:43

2 Answers 2

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
3
  • Very nice! Ty his should be by implemented by default by the distribution creators.
    – dawez
    Commented Jul 24, 2020 at 9: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
    Commented Sep 18, 2020 at 10:12
  • this can be useful to find right device unix.stackexchange.com/a/649206/194331 Commented Feb 24, 2023 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/

1
  • 1
    It simply works. Thanks. Don't know why no one gave an upvote to your answer. someone even gave a downvote. Commented Apr 30, 2022 at 11:21

You must log in to answer this question.

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