Turn Bluetooth On and Off from Command Line on macOS
Bluetooth has been a revelation in wireless technology: wireless mice, headphones, streaming devices, and a variety of home and office environments. It goes without saying that wireless peripherals are so much easier to manage than wired counterparts, especially mice, that I usually have my MacBook's bluetooth turned on.
There are times, however, that I move my laptop away from the mouse (OK, I admit: the kitchen) where the bluetooth connection is still in range but with the mouse still connected, I can't use my laptop's touchpad, leaving me to only use my keyboard which is an annoyance. That led me to finding blueutil, a command line utility for macOS that lets me turn Bluetooth on and off with one command!
Start by installing blueutil with HomeBrew:
brew install blueutil
-p flag is a switch for turning bluetooth on and off:
# Turn bluetooth off blueutil -p 0 # Turn bluetooth on blueutil -p 1
This utility will be so helpful as I move around my house. Since I can't use my touchpad during these situations, I can't turn Bluetooth off from the command bar, so a simple command like this is exactly what I need!