Created
April 12, 2012 17:24
-
-
Save advantis/2369334 to your computer and use it in GitHub Desktop.
Get Magic Mouse battery level
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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