Reporting on Bluetooth Mouse/Keyboard battery status
On the MacEnterprise list (http://lists.psu.edu/archives/macenterprise.html), Michael Edwards posed an interesting question:
Anyone know of a handy way to monitor the status of bluetooth keyboard/trackpad battery levels on remote machines? We have several Mac Mini’s that use them, that are machines with no primary individual user – so it would be handy to get notified (email or similar) when the batteries need to be changed.
So I thought it might be fun to figure out how to answer this.
I first looked at system_profiler:
system_profiler -listDataTypes lists SPBluetoothDataType.
system_profiler SPBluetoothDataType Bluetooth: Apple Bluetooth Software Version: 4.0.8f17 Hardware Settings: Address: 00-26-B0-F5-7B-72 Manufacturer: Broadcom Name: mini Firmware Version: v180 c367 Bluetooth Power: On Discoverable: Yes Vendor ID: 0x5ac Product ID: 0x8216 (snip) Devices (Paired, Favorites, etc): Apple Wireless Mouse: Address: 7c-6d-62-f2-47-2a Type: Mouse Firmware Version: 0x84 Services: Apple Wireless Mouse Paired: Yes Favorite: No Connected: Yes Manufacturer: Apple (0x3, 0x31c) Vendor ID: 0x5ac Product ID: 0x30d EDR Supported: No eSCO Supported: No gneagle’s keyboard: Address: 00-25-bc-fc-29-01 Type: Keyboard Firmware Version: 0x50 Services: Apple Wireless Keyboard Paired: Yes Favorite: No Connected: Yes Manufacturer: Apple (0x3, 0x31c) Vendor ID: 0x5ac Product ID: 0x239 EDR Supported: No eSCO Supported: No (snip)
That doesn’t seem to contain the info we’re looking for.
Next I looked at
ioreg. It doesn’t have very friendly output, but we do what we can.
I first looked for info on anything with “Keyboard” in the name:
ioreg | grep Keyboard | | | | | | +-o AppleBluetoothHIDKeyboard | | | | | | | +-o AppleEmbeddedKeyboard | | | | | | | +-o IOHIDKeyboard
The -c option allows us to get more detail on anything with a specific class.
ioreg -c AppleBluetoothHIDKeyboard returns lots of data, most of which we don’t care about. Visually looking through it, it looked like grepping for “Battery” would narrow things down a bit:
ioreg -c AppleBluetoothHIDKeyboard | grep Battery | | | | | | | "BatteryPanic" = Yes | | | | | | | "BatteryLow" = Yes | | | | | | | "BatteryLowNotificationType" = "LowBattery" | | | | | | | "BatteryDangerouslyLowNotificationType" = "CriticallyLowBattery" | | | | | | | "BatteryPercent" = 12 | | | | | | | "Battery" = <"MVLT0x8f9UT
We can do something similar for “Mouse”:
ioreg | grep Mouse | | | | | +-o BNBMouseDevice
ioreg -c BNBMouseDevice | grep Battery | | | | | | "BatteryPanic" = No | | | | | | "Battery" = <"CHCT0x1CA$ | | | | | | "BatteryLow" = No | | | | | | "BatteryLowNotificationType" = "LowBattery" | | | | | | "BatteryPercent" = 56 | | | | | | "BatteryDangerouslyLowNotificationType" = "CriticallyLowBattery"
I’ll leave it as an exercise for the reader to parse this info even further to get, say, just the BatteryPercent as a number, or just the value of BatteryLow. You could then send an email, open a ticket in your tracking system, update a web page, or whatever makes sense for your organization.Explore posts in the same categories: General, OS X, Scripting