Skip to content

Instantly share code, notes, and snippets.

@advantis
Created April 12, 2012 17:24
Show Gist options
  • Save advantis/2369334 to your computer and use it in GitHub Desktop.
Save advantis/2369334 to your computer and use it in GitHub Desktop.
Get Magic Mouse battery level
#!/bin/sh
percentage=$( ioreg -rS -c BNBMouseDevice -k BatteryPercent -d 1 | grep BatteryPercent | tail -1 | awk '{print $NF}' )
if [ "$percentage" == "" ]; then
echo "Disconnected";
else
if ((50 <= percentage)); then
color=32; #green
elif ((20 <= percentage)); then
color=33; #yellow
else
color=31; #red
fi
echo "\033[${color}mMouse Battery: ${percentage}%\033[0m"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment