Skip to content

Instantly share code, notes, and snippets.

@matthewlmcclure
Created November 17, 2011 00:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewlmcclure/1371983 to your computer and use it in GitHub Desktop.
Save matthewlmcclure/1371983 to your computer and use it in GitHub Desktop.
MacBook Pro Low Battery Notification via Growl
#!/bin/bash
PATH=$PATH:/usr/sbin:/usr/local/bin
system_profiler SPPowerDataType | \
grep ' \(Charging\|Charge Remaining\|Full Charge Capacity\)' | \
cut -d ':' -f 2 | \
{ read remaining;
read charging;
read capacity;
if [ "$charging" != "Yes" ]
then
pctremaining="$(( ${remaining} * 100 / ${capacity} ))";
if [ $pctremaining -lt 10 ]
then
echo "Low Battery: ${pctremaining}% remaining" | growlnotify -s
fi
fi;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment