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


Click here to return to the 'another way' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
another way
Authored by: SOX on Dec 16, '09 09:55:45AM
run this perl script and ever 4 minutes it will test to see if you changed from AC to battery power. if so it will speak "AC shutdown!" one time. After the power is restored the trigger to speak is reset. it runs until you stop it. to make a quick and dirty daemon out of this put this in an automator script and then have it launch at login.

#!/usr/bin/perl -w
while (1) {
$r=`pmset -g batt`;
if ( $r =~ m/AC/) {
   system("touch", "/tmp/powerwatchAC"); }
else {
	if (-f "/tmp/powerwatchAC") { 
    system ("say", "AC shutdown!");
    system("rm","/tmp/powerwatchAC");}
   }
 sleep 240;
}


[ Reply to This | # ]
another way
Authored by: SOX on Dec 16, '09 09:59:50AM
better script.

$s =0;
while (1) {
$r=`pmset -g batt`;
if ( $r =~ m/AC/) {
   $s = 1;}
else {
	if ($s) {
    system ("say", "AC shutdown!");
    $s =0;
   }}
 sleep 240;

}


[ Reply to This | # ]