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
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
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!
- How to list all users in Mac Terminal
- Docker Desktop needs privileged access macOS
- Mac: How to show count of files and folders in Finder
- How to Change Background Color TextEdit on Mac
- How to adjust MacBook Desktop icons size
- Test internet speed using macOS Terminal command
- How to change the default font and text size in Microsoft Excel for Mac
- How to install Java on macOS [Big Sur]
- How to come out of dquote prompt in Terminal - macOS/Linux
- How to Increase MacBook Trackpad Cursor Speed on macOS Ventura/Sonoma
- Fix: Microsoft Excel Quit Unexpectedly on Mac
- How to Adjust macOS System Font Size
- How to Quit Applications on Mac Using Terminal
- How to check zsh installed version using terminal
- Two Ways to Extract rar (*.rar) files on Mac
- How to Right Click on Mac Desktop?
- How to Add Brew to PATH M1/M2 Mac
- How to search (find) in macOS Terminal Console Text
- macOS 13 Ventura - The New About this Mac Window
- TextEdit Get the count of lines in a file
- How to run .sh file in Mac Terminal
- Google Search Hot Trends Screensaver for Mac OS X
- Check Reboot History Mac
- [Solution] Mac Update Stuck Preparing macOS Ventura 13.0 About 30 minutes remaining
- Display Safari URL address link on hover
- [fix] bash: ssh: command not found - Bash
- How to take user input from the console in a Python program - Python
- How to Enable Macros on Excel for Mac - MacOS
- [JEP 431] Java JDK 21 New Feature - Sequenced Collections - Java-JDK-21
- How to clear Mac Terminal screen - MacOS
- Command to display epoch time Terminal - Linux
- Disable Startup Sound on macOS - MacOS
- ls command to sort by date - Linux