Category filter
Script to show Bluetooth menu on status bar of macOS devices
This document helps you display the Bluetooth menu on status bar of macOS devices with the help of a script.
Displaying the Bluetooth status on the menu bar on macOS devices can be a convenient way to check the status of your Bluetooth connection and easily toggle it on or off as needed. This feature allows you to easily check if Bluetooth is enabled or not, whether it is discoverable to other devices, what paired devices exist, and which paired devices are currently active, all without navigating to the device settings. IT admins can use Hexnode’s Execute Custom Script action to execute the script provided below to display the Bluetooth menu on the status bar on macOS devices.
Scripting language – Bash
File extension – .sh
To show Bluetooth status on the menu bar
1 2 3 4 5 6 7 |
#!/bin/bash CurrentUser=$(ls -l /dev/console | awk '/ / { print $3 }') CurrentUserUID=$(id -u "$CurrentUser") launchctl asuser $CurrentUserUID sudo -iu "$CurrentUser" defaults -currentHost write com.apple.controlcenter.plist Bluetooth -int 18 |
The provided Bash script retrieves the username and user ID of the currently logged-in user on the macOS device, and then uses the defaults command to modify the Bluetooth key in the com.apple.controlcenter.plist property list file for the current host. The value of the key is set to 18, which enables the Bluetooth status to be displayed on the menu bar of macOS devices.
To hide Bluetooth status on the menu bar
1 2 3 4 5 6 7 |
#!/bin/bash CurrentUser=$(ls -l /dev/console | awk '/ / { print $3 }') CurrentUserUID=$(id -u "$CurrentUser") launchctl asuser $CurrentUserUID sudo -iu "$CurrentUser" defaults -currentHost write com.apple.controlcenter.plist Bluetooth -int 0 |
The provided Bash script retrieves the username and user ID of the currently logged-in user on the macOS device, and then uses the defaults command to modify the Bluetooth key in the com.apple.controlcenter.plist property list file for the current host. The value of the key is set to 0, which hides the Bluetooth status on the menu bar of macOS devices.
What happens at the device end?
With the execution of this script, the Bluetooth status will be displayed on the menu bar of the Mac, and the option ‘Show in Menu Bar‘ will be enabled in System Settings > Control Centre > Bluetooth. For macOS version 12.0 and below, this option can also be enabled from System Preferences > Dock & Menu > Bluetooth.