Linux shortcut to connect to Bluetooth speakers

We have a Bluetooth speaker in our office that we often use to play music through. My Linux machine, however, didn’t automatically connect to the Bluetooth speaker, and even after connecting it, I’d have to switch the output to be that speaker.

I ended up creating a shortcut on my menu bar that would connect to the Bluetooth speaker and set it as the default audio output, all in one click.

First, I went and set up the audio like I normally would, making sure to note the Mac address of the device:

Ubuntu Bluetooth settings

Then I set that Bluetooth speaker as my default output device:

Ubuntu sound settings

Then I checked on my pulseaudio settings to see what name Pulseaudio gave that device:

~$ pactl stat
Currently in use: 146 blocks containing 477.3 KiB bytes total.
Allocated during whole lifetime: 13740809 blocks containing 2.0 GiB bytes total.
Sample cache size: 355.8 KiB
Server String: unix:/run/user/1000/pulse/native
Library Protocol Version: 28
Server Protocol Version: 28
Is Local: yes
Client Index: 494
Tile Size: 65472
User Name: eric
Server Name: pulseaudio
Server Version: 4.0
Default Sample Specification: s16le 2ch 44100Hz
Default Channel Map: front-left,front-right
Default Sink: bluez_sink.12_34_56_78_90_AB
Default Source: alsa_input.pci-0000_00_1b.0.iec958-stereo
Cookie: 2f41:4d31

Finally, I wrote a shell script that would connect to the device and then set it as the default audio output:

bt-audio -c 12:34:56:78:90:AB
pactl set-default-sink bluez_sink.12_34_56_78_90_AB

Marking the script as executable and then dragging it to my menu bar gave me an easy-to-use shortcut.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>