Skip to content

Instantly share code, notes, and snippets.

@matthewlmcclure
Created November 17, 2011 00:25
Show Gist options
  • 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