π§π AirPods (well, any bluetooth) alias for MacOS
This is a short π©³; a note that doesn’t merit a full post. See all shorts here.
So, one early morning, and Iβm just getting my coffee. For fun, letβs automate
connecting to bluetooth AirPods without touching the mouse. Quick Google
brings up blueutil
, and a tiny bit of jq
was all the glue needed:
brew install blueutil
blueutil --connect $(blueutil --paired --format json-pretty | jq -r ".[] | select(.name | contains(\"Shayβs AirPods Pro\")) | .address)
The first time you run this, you’ll need to give the terminal permission to get access to bluetooth:
Youβll need to change the contains
to your device. The alias:
alias airpods='blueutil --connect $(blueutil --paired --format json-pretty | jq -r ".[] | select(.name | contains(\"Shayβs AirPods Pro\")) | .address")'
And finally, if you have multiple devices, I’ve found that configuring an alias
per one is the best. If you still prefer to just use one alias, here’s a bttui
(pronounced like Ratatouille) alias which utilizes
gum
to choose which device to connect
to. It even filters out the currently connected devices:
alias btgui='blueutil --connect $(blueutil --paired --format json-pretty | jq -r ".[] | select(.name | contains(\"$(blueutil --paired --format json-pretty | jq -r ".[] | select(.connected | not) | .name" | gum choose)\")) | .address")'
Why?
Well, why not?
I got a pair of AirPods back when I joined Orca. That’s really cool, and ever since I joined, my daily routine on days when I work from the office has been:
- Connect to AirPods on my phone.
- Listen on my commute (Normally, bicycle or bus; Rarely, car).
- I normally listen to music, but sometimes I listen to podcasts - right now re-listening to The Adventure Zone.
- Step into the office, AirPods back into the case to say good morning.
- Run my
morning
alias in my terminal, which sets up things I need for the day, like a draft blogpost on Confluence and logging into various corporate MFA things so they don’t abruptly interrupt me while I’m focused. - Connect to AirPods on my laptop to continue listening to whatever music or podcast I’ve been listening to.
Having the morning
routine set up but not having it do the last touch of
connecting to my AirPods? Not ππ.
Shorts?
This is my first short; a note that doesn’t merit a full post. Inspired by Brandur Leach’s beautiful corner of the web, my hope is that this short-form, more than a tweet, less than a post format will help me publish more often.