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
The -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!
Thanks for sharing this! I was trying to find an easier way to toggle Bluetooth and I kept finding articles about AppleScript, but this is way easier for people familiar with the command line.
Thank you! I just came across this and it was a life-saver.
I created a small “bluetoggle.sh” to toggle the switch: ON if it was OFF, OFF if it was ON. I then used iCanHazShortcut to map the script to [^B] for ease of access.
The code above was messed up by the interpreter (symbol ` is not accepted it seems). I put here the final code of my 1-line bluetoggle.sh
https://pastebin.com/YssdgD5Z
This can be turned into a toggle command using:
Thanks for this. Bluetooth has been crashing on my mac every so often, so a quick brew install and 2 aliases and I’m in business.
Here is how I control my bluetooth from ZSH.