Bluetooth is the most popular wireless technology which has become an integral part of our daily lives. Whether you're connecting wireless AirPods or headphones, keyboards, or mice, or to share files from other devices using AirDrop, or even controlling devices, Bluetooth plays a key role in today's computing.
If you have a macOS device and looking to take control of your Bluetooth settings from the command line or Python or Shell Script, blueutil is the tool you can make use of. In this article, we explore how to make use of blueutil to manage Bluetooth on your Mac.
What is blueutil?
blueutil is a command-line utility designed specifically for macOS that empowers us to control various Bluetooth using the terminal. We can turn Bluetooth on or off, list paired devices, inquire about nearby devices, or even connect and disconnect.
Installation
Before diving into the commands, you'll need to install blueutil. If you haven't already, you can do so using Homebrew, the popular package manager for macOS. Open your terminal and run the following command.
brew install blueutil
Basic Usage:
Let's start with the basics. Running blueutil without any options will output the current state of your Bluetooth:
blueutil
Power: 1
Discoverable: 0
![blueutil - Example blueutil - Example](https://code2care.org/howto/bluetooth-on-mac-terminal-using-blueutil-commands/images/blueutil - Example.jpg)
You'll see information about the power state and discoverable state of your Bluetooth.
Turning Bluetooth On and Off
You can turn Bluetooth on or off using blueutil with the -p or --power option, followed by the desired state (1 for on, 0 for off):
Example: Turn Bluetooth on
blueutil --power 1
Example: Turn Bluetooth off
blueutil --power 0
Checking Discoverable State
The discoverable state of your Bluetooth can also be checked and set using blueutil:
Example: Check discoverable state
blueutil --discoverable
BS|Example: Set discoverable state (1 for discoverable, 0 for non-discoverable)
blueutil --discoverable 1
![blueutil --discoverable 1 blueutil --discoverable 1](https://code2care.org/howto/bluetooth-on-mac-terminal-using-blueutil-commands/images/blueutil --discoverable 1.jpg)
Exploring Devices
blueutil provides several commands to explore and interact with Bluetooth devices.
Listing Paired Devices
blueutil --paired
Inquiring Nearby Devices
To discover nearby devices, you can use the --inquiry option. By default, it will scan for devices for 10 seconds:
blueutil --inquiry
Listing Connected Devices
To list the devices currently connected to your Mac, use the following command:
blueutil --connected
Managing Individual Devices
blueutil --info <device_id>
Connecting and Disconnecting
To create a connection with a device, use the --connect option followed by the device's ID:
blueutil --connect <device_id>
Conversely, you can close a connection to a device using the --disconnect option:
blueutil --disconnect <device_id>
Pairing and Unpairing
Pairing with a device is straightforward. Use the --pair option, followed by the device's ID. If required, you can also provide a PIN of up to 16 characters:
blueutil --pair <device_id> [PIN]
To unpair a device, you can use the --unpair option:
blueutil --unpair <device_id>
Adding and Removing from Favorites
blueutil --add-favourite <device_id>
Conversely, you can remove a device from your favorites list using the --remove-favourite option:
blueutil --remove-favourite <device_id>
Advanced Options
Advanced Options | Description |
---|---|
--format FORMAT | Change output format for device information and listing commands. |
--wait-connect ID [TIMEOUT] | Wait for a device to connect (EXPERIMENTAL). |
--wait-disconnect ID [TIMEOUT] | Wait for a device to disconnect (EXPERIMENTAL). |
--wait-rssi ID OP VALUE [PERIOD [TIMEOUT]] | Wait for a device's RSSI (Received Signal Strength Indicator) value (EXPERIMENTAL). |
Waiting for Events
blueutil provides experimental options to wait for specific events related to devices:
--wait-connect: Wait for a device to connect.
--wait-disconnect: Wait for a device to disconnect.
--wait-rssi: Wait for a device's RSSI (Received Signal Strength Indicator) value.
Exit Codes
blueutil returns exit codes that can help you understand the result of your command:
Exit Codes | Description |
---|---|
0 | Success. |
1 | General failure. |
64 | Wrong usage, such as missing or unexpected arguments. |
69 | Bluetooth or interface not available. |
70 | Internal error. |
71 | System error, like a shortage of memory. |
75 | Timeout error. |
Facing issues? Have Questions? Post them here! I am happy to answer!
Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.
Follow him on: X
You can also reach out to him via e-mail: rakesh@code2care.org
- Fix: grunt: command not found (Mac/Windows)
- AppleScript Example with TextEdit
- How to copy Password of Wifi on your Mac
- Install OpenJDK Java (8/11/17) versions using brew on Mac (Intel/M1/M2)
- How to check if a port is in use using terminal [Linux or macOS]
- Cut, Copy and Paste Keyboard Shortcuts on Mac Keyboard
- [macOS] NetBeans IDE cannot be installed. Java (JRE) found on your computer but JDK XX or newer is required.
- How to Remove Widgets from macOS Sonoma 14 Desktop
- Turn off Auto-Capitalization on macOS Ventura 13
- How to Go To /usr/local/bin on Mac Terminal?
- How to Open TextEdit on Mac
- Mac: How to Open Android Studio from Terminal
- How to change the default location of Mac Screenshot
- Display Seconds in Digital Clock on Mac Menu Bar [macOS]
- How to install homebrew (brew) on M1 Mac
- Must Know Homebrew Commands for Mac/Linux Users
- Steps to Uninstall Roblox on Mac (macOS)
- How to change the System Settings Sidebar icon size Mac Ventura 13
- How to set Out Of Office (OOO) on Outlook for Mac [Updated 2023]
- Trigger Notification Center Message using Mac Terminal Command
- [fix] macOS Ventura - Python3 xcrun: error: invalid active developer path missing xcrun at CommandLineTools
- How to Install Rust Language on Mac (macOS)
- How to minimize all Windows in Mac
- Display ls command file sizes in KB (kilobytes) MB (megabytes) or GB (gigabytes) [Linux/macOS]
- How to make TextEdit the default text Editor on Mac
- How to know file encoding in Microsoft Windows Notepad? - Microsoft
- Submit html form on dropdown menu value selection or change using javascript - JavaScript
- [Android] This view is not constrained vertically: at runtime it will jump to the top unless you add a vertical constraint - Android
- How to adjust MacBook Desktop icons size - MacOS
- How to check if a variable is set in Bash Script or Not - Bash
- How to enable Do Not Disturb (DND) mode in Microsoft Teams - Teams
- Install Bash Completion on macOS - Bash
- Program 10: Modulo of Two Numbers - 1000+ Python Programs - Python-Programs