Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Notify yourself periodically using Growl' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Notify yourself periodically using Growl
Authored by: devan on Sep 28, '07 08:45:30AM
I had to do something like this to let myself know when my battery's getting drained. I've taken my battery icon out of the menu bar, and put status on my desktop, using GeekTool. (Details here, in the comments. Not the point.) The problem is, my 20% battery power warnings no longer show up. So I used growlnotify and a launchd agent to alert myself when things get low. Using launchd, I run this shell script (which I've called batteryAlert.sh and placed in /usr/local/bin) every 300 seconds:
#!/bin/bash
# get battery charge (in mA, I think)
rem=`system_profiler SPPowerDataType | grep "Remaining" | cut -c 33-36`
# is charge less than 800 (out of a possible 4300 or so)?
if [ "$rem" -lt "800" ]
then
# tell me about it using growl
	/usr/local/bin/growlnotify -n batteryAlert -p High "Battery getting low..."
fi
If you wanted an alternative to using growlnotify, try going with AppleScript, replacing the line containing the growlnotify call with the following:
osascript -e 'tell application "Finder"' -e "activate" -e "display dialog "Battery getting low..."" -e 'end tell'
This has the disadvantage of requiring you to click "OK" to dismiss the dialog; maybe there's a better way...

[ Reply to This | # ]
Notify yourself periodically using Growl
Authored by: wallybear on Oct 01, '07 02:12:57AM
If you want to dismisss the dialog automatically, just change the command to this:

display dialog "Battery getting low..." buttons {"OK"} giving up after 2

the "buttons" part is optional, it makes the dialog showing only the OK button the "giving up" part makes the dialog dismiss itself after x seconds (2 in the example).

[ Reply to This | # ]
Low battery warning AppleScript
Authored by: TinyApps.Org on Dec 27, '09 04:49:56PM
Thanks for the script! Here it is updated for Snow Leopard with the AppleScript typo fixed as well:
#!/bin/bash

rem=`system_profiler SPPowerDataType | grep "Charge remaining" | sed 's/[^0-9]//g'`

if [ "$rem" -lt "800" ]

then

osascript -e 'tell application "Finder"' -e "activate" -e 'display dialog "Low battery warning"' -e 'end tell'

fi


[ Reply to This | # ]