Score:0

Automatically Select Bluetooth Headset Microphone as Input Device in Sound Settings on Connection

in flag

I have a Jabra Evolve 75 headset that I connect via Bluetooth to my Ubuntu 20.04 machine. Everything works fine in principle except for one little annoyance:

Whenever I turn the headset on, it connects and the Output Device is automatically set accordingly in the Sound Settings. This is the way I want it. However, the Input Device remains like it was set before and I manually have to go in to the settings and also change it to Jabra Evolve 75:

enter image description here

How can I configure the settings so that both Input Device and Output Device automatically switch to Jabra Evolve 75 once I turn the headset on?

user3569063 avatar
at flag
I'm having the same problem. Bose QC35, waiting for a good answer. This post is talking about the same thing: https://askubuntu.com/questions/831331/failed-to-change-profile-to-headset-head-unit Not sure if it is still valid on ubuntu 22.04 or not.
buddemat avatar
in flag
@aaronsun: I found a way to fix it for my purposes, see answer below...
us flag
Same problem - I wonder why it's not working out of the box like on mac or windows :/
Score:2
in flag

Ok, I finally found how to automatically switch to the HFP audio profile, which will then also automatically set the headset microphone as input device.

There are multiple approaches around, but the only way to do this automatically when connecting the bluetooth headset seems to be to create a udev rule which runs a script when the headset is connected. There is a very nice blog post that describes this in-depth which I used to achieve what I wanted and where most of the code below is originally from.

These are the essential steps:

  1. Find out card name and profile using pactl list. The output contains two lines that you will need:

    ...
    Card #20
        Name: bluez_card.70_BF_92_C9_F5_D0
        ...
     Profiles:
         a2dp_sink: High Fidelity Playback (A2DP Sink) (sinks: 1, sources: 0, priority: 40, available: yes)
         handsfree_head_unit: Handsfree Head Unit (HFP) (sinks: 1, sources: 1, priority: 30, available: yes)
         off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
    ...
    

    In this example, the card name is bluez_card.70_BF_92_C9_F5_D0 and the profile name is handsfree_head_unit.

  2. With that, create a script ~/.config/auto-pactl.sh to switch the headset to the HFP profile:

    #!/bin/bash
    sleep 2 # wait for the headset to fully connect                                 
    sudo -u '#1000' XDG_RUNTIME_DIR=/run/user/1000 \                                
        pactl set-card-profile bluez_card.70_BF_92_C9_F5_D0 handsfree_head_unit     
    logger "Switched Jabra headset to HFP profile"
    
  3. Find out input name of headset using udevadm monitor and then connecting the BT headset. The output should be something like:

    ...
    UDEV  [54588.946048] add      /devices/virtual/input/input112 (input)
    ...
    
  4. Find out subsytem, vendor, and product using udevadm info -ap /devices/virtual/input/input112 (replacing the device with whatever the previous command's output was)

  5. With this information, create a udev rule to execute the above script and store it in /etc/udev/rules.d/52-jabra-headset.rules, inserting the values for your card and your username in the appropriate places:

    ACTION=="add", SUBSYSTEM=="input", ATTR{id/vendor}=="0067", ATTR{id/product}=="24a7", RUN+="/home/<myUsername>/.config/auto-pactl.sh"
    

That worked like a charm for me!

buddemat avatar
in flag
BTW: This also works on Mint 21.1
us flag
The Configuration does not change - but the input device changes :) Ubuntu 22.04.2
Tai Truong avatar
eh flag
Small detail missing, u need to add in auto-pactl.sh this in first line: #!/bin/bash
buddemat avatar
in flag
@TaiTruong Thanks, you're right, I forgot the shebang in this post (though I had it in my local script). I've updated my answer.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.