🎧🍏 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:

ITerm Bluetooth Permissions popup

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:

  1. Connect to AirPods on my phone.
  2. Listen on my commute (Normally, bicycle or bus; Rarely, car).
    1. I normally listen to music, but sometimes I listen to podcasts - right now re-listening to The Adventure Zone.
  3. Step into the office, AirPods back into the case to say good morning.
  4. 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.
  5. 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.