Auto-Switching your Bluetooth headset using SystemD

Make your Bluetooth headset the default output.


1 min read

I've been struggling with this for quite some time, but today I wanted to fix this somehow.

I use Pipewire which has a pipewire-pulse package on Archlinux that interfaces with PulseAudio applications.

However, I had to manually switch the sink to make my Bluetooth device the default.

Usually, one can do

pactl list sinks short


pactl set-default-sink <sink-name>

This will set it, which is what I do via the system tray option. But I wanted an automated solution.

At first, I tried to use udev but I couldn't figure it out, but SystemD made it easy.

So I created a file under /home/leon/.config/systemd/user/switch_bt.service with the following content

Description=Switch sink to the Bluetooth device

ExecStartPre=/bin/sleep 10


To find the PCI device you can do systemctl --all -t device, you can search for the hciservice.

Then I simply enabled the systemctl --user service.

$ systemctl --user daemon-reload
$ systemctl --user enable switch_bt.service
$ systemctl --user switch_bt.service

The contents of is


pactl list sinks short
pactl set-default-sink bluez_output.EB_06_EF_5E_E6_77.a2dp-sink

/usr/bin/notify-send 'Changing Default Sink' --expire-time=4000

So whenever I connect the Bluetooth device it waits for some time and then auto switches the sink to my Bluetooth device.