Q:

Read Magic Mouse and Apple Wireless Keyboard Battery percentage

I want to ask you If anybody know a simple way to access Mouse and Keyboard battery state in Mac OS. There are some API to access this information? Thanks!

A:

For the Keyboard it is: 
ioreg -n "IOAppleBluetoothHIDDriver" | grep -i "batterypercent" | sed 's/[^[:digit:]]//g'

and for the Magic Mouse it is:
ioreg -n "BNBMouseDevice" | grep -i "batterypercent" | sed 's/[^[:digit:]]//g'

