Is there a simple MacOS Bluetooth Toggle Shell Command?

I have found this answer that shows how to toggle WiFi using a keyboard shortcut: https://apple.stackexchange.com/a/194372/406298.

I have created a new Action in the automater app to run the shell command provided in the answer:

networksetup -getairportpower en1 | grep "On" && networksetup -setairportpower en1 off || networksetup -setairportpower en1 on

Then, I have added the Actions shortcut in the keyboard's Touchbar to toggle WiFi from the Touchbar.

This works great as a quick WiFi toggle from the touchbar. However, I would like to do the same for Blutooth. Is there a similar simple shell command to toggle Bluetooth?

Thank you in advance.


There is a third-party utility named blueutil that makes it easy:

blueutil --power toggle

Toggles the Bluetooth power state.

See the Usage section on the linked webpage for additional usage information.

Note: If you do toggle the power state, turning Bluetooth off, make sure you can control your Mac's keyboard via USB or built-in if a notebook.