Auto-Switching your Bluetooth headset using SystemD
Make your Bluetooth headset the default output.
Search for a command to run...
Make your Bluetooth headset the default output.
No comments yet. Be the first to comment.
As the title says I'm documenting my entire Khadas Edge 2 journey. I'm a huge fan of tablets. I like the screen size they come with and the features. But is it perfect to replace my day-to-day machine? Heck no. I run containers and kubernetes and wha...

Well like all good things come to an end, so has my journey with my Raspberry Pi 2B which has been here for almost a decade. It's a nifty little device, and with 1 GB of ram everything was possible from running a Pi-hole DNS server to running a Pytho...

Well I've been trying to contribute to the risc-v ecosystem, and usually I get either overwhelmed by what I'm doing or I get bored... but I do work well when I've got a task on hand, like the one I took below! I've been a fan of what Jeff Geerling d...

Hello everyone, it's been a while since I've written anything since I'm always busy. So this article will explain a simple concept that many fail to recognize and I did too. The concept I'm talking about is called "Connection Termination", there coul...

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
Then
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
[Unit]
Description=Switch sink to the Bluetooth device
After=sys-subsystem-bluetooth-devices-hci0:256.device
After=sys-devices-pci0000:00-0000:00:14.0-usb1-1\x2d7-1\x2d7:1.0-bluetooth-hci0-hci0:256.device
BindsTo=sys-subsystem-bluetooth-devices-hci0:256.device
BindsTo=sys-devices-pci0000:00-0000:00:14.0-usb1-1\x2d7-1\x2d7:1.0-bluetooth-hci0-hci0:256.device
[Service]
ExecStartPre=/bin/sleep 10
Type=oneshot
ExecStart=/home/leon/.config/switch_bt.sh
[Install]
WantedBy=sys-subsystem-bluetooth-devices-hci0:256.device
WantedBy=sys-devices-pci0000:00-0000:00:14.0-usb1-1\x2d7-1\x2d7:1.0-bluetooth-hci0-hci0:256.device
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 switch_bt.sh is
#!/bin/sh
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.