Skip to content

Instantly share code, notes, and snippets.

@ashtom
Created July 13, 2011 12:31
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 ashtom/1080210 to your computer and use it in GitHub Desktop.
Save ashtom/1080210 to your computer and use it in GitHub Desktop.
Show a growl notification every minute if battery is below threshold
#!/bin/bash
#
# Show a growl notification every minute if battery is below threshold.
#
# Setup:
# 1. Install growlnotify
# 2. Adjust threshold in line 20 (here 656mAh)
# 3. Create line in crontab like this:
# * * * * * /path/to/script/battery_low.sh
charger=`/usr/sbin/system_profiler SPPowerDataType | grep "Connected:"`
if [[ "$charger" == *Yes* ]]
then
exit
fi
rem=`/usr/sbin/system_profiler SPPowerDataType | grep -i "Charge remaining" | sed 's/[^0-9]//g'`
if [ "$rem" -lt "656" ]
then
/usr/local/bin/growlnotify -n batteryAlert -p High -m "Battery getting low... ($rem mAh)"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment