How to Check Bluetooth Keyboard Battery Levels from the Command Line on Mac OS X

May 18, 2014 - 8 Comments

Get Bluetooth battery life from the command line of 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.

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:

Bluetooth Battery Level seen from the Command Line in Mac OS X

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.

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: Paul Horowitz in Command Line, Mac OS X, Tips & Tricks


» Comments RSS Feed

  1. Craig D. Miller says:

    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\ \
    -s -p 2 -t "ATTENTION" -H Craigs-Mac \
    -m "Mouse battery low on ${myhost}: ${mbatt}%"

    I obviously also do same for keyboard, and leave the coding to the reader.


  2. Dan Westbrook says:

    Can also check the mouse with this command: ioreg -c BNBMouseDevice |grep ‘”BatteryPercent” =

  3. dderusha says:

    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!

Leave a Reply


Shop on and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks


iPhone / iPad