9

This geeklet shows the following:

  • Current system battery charge
  • System battery health
  • System battery cycles
  • Magic Mouse charge / disconnected
  • Magic Trackpad charge / disconnected
  • Wireless keyboard charge / disconnected

Screenshot

Code:

ioreg -l | grep -i capacity | tr 'n' ' | ' | awk '{print ("System Battery: ",$10/$5 * 100,"%")}';
osascript -e 'set a to do shell script "ioreg -w0 -l | grep Capacity"' -e "set h to word 5 of a" -e "set z to word 33 of a" -e "set b to word 38 of a" -e "set c to 1000 * b / z" -e "set d to round c" -e "set f to d / 10" -e "set q to 1000 * h / b" -e "set w to round q" -e "set j to w / 10" -e '"Battery Health: " & j &"%"' | iconv -f utf-8 -t ucs-2-internal;
ioreg -w0 -l | grep "Cycle Count" | awk 'BEGIN { FS = "=" } ; {print $8}' | awk 'BEGIN { FS = "}" } ; {print $1, "Cycles"}';

kbatt=`ioreg -c AppleBluetoothHIDKeyboard | grep BatteryPercent | tail -1|awk '{print $9}'`;
tbatt=`ioreg -c BNBTrackpadDevice | grep BatteryPercent | tail -1|awk '{print $10}'`;
mbatt=`ioreg -c BNBMouseDevice | grep Percent | tail -1| awk '{print $9}'`;
if [ ${#mbatt} -lt 1 ]; then
    echo "Magic Mouse: disconnected"
else
    echo "Magic Mouse Battery: $mbatt%"
fi
if [ ${#tbatt} -lt 1 ]; then
    echo "Magic Trackpad: disconnected"
else
    echo "Magic Trackpad Battery: $tbatt%"
fi
if [ ${#kbatt} -lt 1 ]; then
    echo "Wireless Keyboard: disconnected"
else
    echo "Wireless Keyboard Battery: $kbatt%"
fi

If the length of result of the ioreg commands are smaler than 1, the script assumes the peripheral as disconnected.

Geeklet files to download

Comments

User Avatar
rcox1963 2941 days ago
Very nice geeklet. Ran into one issue.

I have a Mighty Mouse attached to my MacBook via bluetooth. The status is showing as "disconnected"; it is connected and (as of this moment) is at 41% battery power.

I see your note above: "If the length of result of the ioreg commands are smaler than 1, the script assumes the peripheral as disconnected."

I am running the latest version of Snow Leopard (10.6.7).

Any thoughts on my getting "disconnected" when Mighty Mouse is connected.

Thank

Bob
User Avatar
Bat 2896 days ago
me need mac os x lion magic mouse & keyboard status info help pls
User Avatar
Geekism 2806 days ago
"Disconnected" on both keyboard and trackpad, eventhough they are obviously connected and operational.

Log in to comment or register here.