How to Check Bluetooth Keyboard Battery Levels from Command Line on Mac OS X
Ever needed to remotely check the battery level of a Bluetooth keyboard connected to a Mac? Or maybe you’re just a heavy Terminal user and wanted to see the current battery life of a wireless keyboard without having to leave the command line? You can do that easily through the Terminal of either a remote or local Mac.
It should be mentioned that most Mac users are best served checking their attached Bluetooth devices battery levels directly from the Bluetooth menu, but advanced users may find this command line approach to be appealing, even if for just specific use cases.
How to Find Keyboard Battery Level from Command Line on Mac
Use the following command syntax to retrieve the battery level of any Bluetooth keyboard connected to a Mac, you may want to copy and paste this as shown to have precise syntax. As usual with terminal commands, be sure the entire command string is printed on a single line:
ioreg -c AppleBluetoothHIDKeyboard |grep '"BatteryPercent" ='
Executing the command returns output looking something like the following:
$ ioreg -c AppleBluetoothHIDKeyboard |grep '"BatteryPercent" ='
"BatteryPercent" = 12
In this example, the “12” is the percentage remaining of the Bluetooth devices battery.
If you feel like it, you can double-check the accuracy by looking at the standard Bluetooth battery remaining menu item for that device:
This works great for local and remotely connected Macs through SSH, so there are plenty of uses for this command.
Having the series of quotations is necessary to avoid a bunch of unnecessary output returned by ioreg. Yes, you could pass the grep and ioreg output through awk to get cleaner results, but we’re aiming to keep it simple here. Nonetheless, if you want to experiment yourself, you can try with the following ioreg:
ioreg -c AppleBluetoothHIDKeyboard |grep BatteryPercent
Or to retrieve broader battery information:
ioreg -c AppleBluetoothHIDKeyboard |grep Battery
Let us know in the comments if you have an ideas or find any other useful tricks with this command.
Just click on System Preferences, then click on keyboard. You will see the battery level at the lower left corner of the window.
Oh Will, you madlad.
Any information for MacOS 10.14.2 with Beats Solo 2? I’m trying to update a script. I see them in the system_profiler (not the battery percentage) and I’m not finding battery percentage in ioreg.
Thanks in advance!
system_profiler SPBluetoothDataType
—
Devices (Paired, Configured, etc.):
Pete – Solo 2:
Address: xxx-xxxx-xxxxx-xxxx-xx [**removed**]
Major Type: Audio
Minor Type: Headphones
Services: Hands-Free unit
Paired: Yes
Configured: Yes
Connected: Yes
Manufacturer: Cambridge Silicon Radio (0x6, 0x2A08)
Firmware Version: 0x0100
Vendor ID: 0x290B
Product ID: 0x0600
Class of Device: 0x04 0x06 0x240418
RSSI: -46
Role: Master
Connection Mode: Active Mode
Interval: 0 ms
EDR Supported: Yes
eSCO Supported: Yes
SSP Supported: Yes
—
If I check the same datatype using ioreg -n “SPBluetoothDataType” I’m not seeing it listed.
I had to remove the “” from BNBMounseDevice
ioreg -n “BNBMouseDevice” | grep -i ‘”BatteryPercent” =’
otherwise it errored saying no file or directory
ioreg -n BNBMouseDevice | grep -i ‘”BatteryPercent” =’
this will be helpful thank you!
Can also check the mouse with this command: ioreg -c BNBMouseDevice |grep ‘”BatteryPercent” =
Great additional tip, thanks Dan!
I guess I made my mouse comment too complicated???
I use this nightly to test keyboard and mouse levels. When too low I growl (persistent) that batteries need change. This allows me to keep my wife’s batteries topped off, without her being stuck (battery changing is my job).
For the mouse use:
ioreg -n “BNBMouseDevice” | grep -i ‘”BatteryPercent” =’
And in nightly batch file to check level (zsh):
mbatt=`ioreg -n “BNBMouseDevice” | grep -i ‘”BatteryPercent” =’|sed ‘s/[^[:digit:]]//g’`
if [[ -n $mbatt ]] && ((mbatt <= 20)); then
growlnotify -a /Applications/System\ Preferences.app \
-s -p 2 -t "ATTENTION" -H Craigs-Mac \
-m "Mouse battery low on ${myhost}: ${mbatt}%"
fi
I obviously also do same for keyboard, and leave the coding to the reader.
Craig
Great added trick, thanks Craig!
Do you know any way to get same info for Apple Magic Trackpad?
I’m very late to the party, but, for posterity:
The Magic Trackpad bluetooth name is: BNBTrackpadDevice
So, use it as:
ioreg -c BNBTrackpadDevice | grep ‘”BatteryPercent” =’