Skip to content

Instantly share code, notes, and snippets.

@desbo
Last active February 17, 2021 12:26
Show Gist options
  • Save desbo/66a9fca168ff14ceb9d7dc3ab0a146dc to your computer and use it in GitHub Desktop.
Save desbo/66a9fca168ff14ceb9d7dc3ab0a146dc to your computer and use it in GitHub Desktop.
disconnect/reconnect bluetooth headphones on mac sleep/wake
  1. install blueutil (cli app to control bluetooth) and sleepwatcher (run commands on sleep and wake)
brew install blueutil sleepwatcher
  1. find the address of your headphones with blueutil
> blueutil --paired
address: cc-98-8b-56-61-bd, connected (master, -45 dBm), not favourite, paired, name: "WH-1000XM3"
  1. create ~/.sleep and ~/.wakeup files:
  • ~/.sleep
#!/usr/bin/env bash

/usr/local/bin/blueutil -p 0
  • ~/.wakeup (note the headphone address from before):
#!/usr/bin/env bash

/usr/local/bin/blueutil -p 1
sleep 0.5
/usr/local/bin/blueutil --connect cc-98-8b-56-61-bd
  1. make scripts executable
chmod +x .sleep .wakeup
  1. make sleewpwatcher run on startup
brew services start sleepwatcher
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment