Page 1 of 1

Auto switch to bluetooth headphones

Posted: Mon Jan 16, 2023 5:57 am
by kloos
Hi all,

A recent trip to another distro showed me that my Bluetooth headphones connected and were auto-selected.

Back in MX, which is so much better in many other ways... I have to manually select the headphones in the sound option every time I connect them. If I don't, the sound comes out of the laptop.

Is there a way to automate the switch in MX?

Thanks

Re: Auto switch to bluetooth headphones

Posted: Mon Jan 23, 2023 12:55 pm
by RallyDarkstrike
Seconding this as I only realized and found out about this last night....

Running Linux Mint MATE on my Lenovo Thinkpad T520, the second I connect my JVC Bluetooth headphones, the audio is happily transferred over automatically, but I was stumped for a second at first when I tried it on my HP Stream last night with the same headphones and the noise kept coming out of the speakers!

Re: Auto switch to bluetooth headphones

Posted: Fri Mar 22, 2024 3:00 pm
by Eadwine Rose
Please share your full Quick System Info, found in the menu. Press the Copy for forum button, then click paste in a reply.. thanks.


Oh.. I thought a post by a new person was asking for help. *chuckles*

Re: Auto switch to bluetooth headphones

Posted: Fri Mar 22, 2024 3:08 pm
by mxUs3r
Hi

I had the same problem and solved it with single command run in the terminal:

Code: Select all

pactl load-module module-switch-on-connect
and it worked like charm, but it was not persistent,
after reboot I needed to run the same command every time. I tried different solutions from forums around, but nothing worked.
I spend 5-6 hours and grabbing peaces from those forums - I solved it:

1. I created a shell script with that command above:

Code: Select all

#!/bin/sh

sleep 12s
pactl load-module module-switch-on-connect
exit 0
2. Saved it as "auto-switch-nk.sh" in "~/.config" folder (you can save it in your home folder if you want)
3. I used "Sessions and Startup" tool to create auto start entry:
4. On tab "Application Autostart" click "+Add" button
5. Fill the fields as below:

Name: auto-switch
Description: <put whatever you want here>
Command: - I clicked the folder icon along this field and indicated to that shell script above in ".config" folder
Trigger: on login

-- after reboot it did not work, then I:

4. opened the the file that "Sessions and Startup" created for me "nano ~/.config/autostart/auto-switch-nk.desktop"
5. Added "sh" right after "Exec=" on line 7. (if it's there in your case - just ignore this)
This is what the file "auto-switch-nk.desktop" looked like eventually:

Code: Select all

[Desktop Entry]
Encoding=UTF-8
Version=0.9.4
Type=Application
Name=auto-switch-nk
Comment=Auto switch to bluetooth headphones
Exec=sh /home/USER_NAME/.config/auto-switch-nk.sh
OnlyShowIn=XFCE;
RunHook=0
StartupNotify=false
Terminal=false
Hidden=false
!! Don't forget to replace "USER_NAME" with your actual username in the field above

After reboot - I have it working.

Hope this helps =)

Re: Auto switch to bluetooth headphones

Posted: Fri Mar 22, 2024 3:11 pm
by mxUs3r
Ohh, I am sorry, My post is duplicated, I messed with "Preview and Submit" buttons.
Please just remove the top one, I guess the lower post is shorter and more understandable.
Thanks

Re: Auto switch to bluetooth headphones

Posted: Fri Mar 22, 2024 3:16 pm
by Eadwine Rose
Done. Hope I removed the one you intended to go :)

Re: Auto switch to bluetooth headphones

Posted: Fri Mar 22, 2024 3:16 pm
by Charlie Brown
There was even a request by @CharlesV for it to be "ootb":

viewtopic.php?t=78678

Re: Auto switch to bluetooth headphones

Posted: Fri Mar 22, 2024 4:03 pm
by mxUs3r
Thanks
yes, you removed the one I intended.
I did not find that post (78678) to follow before I managed it my way =)

I've just looked into the file:

Code: Select all

/usr/share/pipewire/pipewire-pulse.conf
Or the guy miss spelled it or the config file changed since then.

I could not find any:

Code: Select all

content.exec:
in that file , but I think he means this part/block of the file:

Code: Select all

context.exec = [
    { path = "pactl"        args = "load-module module-always-sink" }
    { path = "pactl"        args = "upload-sample my-sample.wav my-sample" }
    { path = "/usr/bin/sh"  args = "~/.config/pipewire/default.pw" }