Whenever I connect/disconnect my bluetooth headphones to my Linux workstation, I need to manually switch to/off them.
Every commercial OS I’m aware of does that automatically, including Chrome OS, macOS and Windows.
To automate this behavior on Linux, it depends whether we’re using PulseAudio or Pipewire. It boils down to loading the module-switch-on-connect
pulseaudio module.
Note: Tested on Arch Linux only.
PulseAudio
$ sudoedit /etc/pulse/default.pa
...
load-module module-switch-on-connect
...
Then restart pulseaudio:
$ systemctl --user restart pulseaudio
PipeWire
$ sudo mkdir -p /etc/pipewire
$ sudo cp /usr/share/pipewire/pipewire-pulse.conf /etc/pipewire/pipewire-pulse.conf
$ sudoedit /etc/pipewire/pipewire-pulse.conf
...
# Extra modules can be loaded here. Setup in default.pa can be moved here
context.exec = [
{ path = "pactl" args = "load-module module-switch-on-connect" }
]
...
Alternatively, ~/.config/pipewire/pipewire-pulse.conf
should also work. We
should not edit the file in /usr
because it will not survive package
upgrades.
Then restart pipewire:
$ systemctl --user restart pipewire{,-pulse}