I don't know if there exists something better, but I couldn't find it, and I was curious anyway, and so I wrote my own.
I need to wake my computer at 3 a.m. to run nightly backups (using Backup.app from mac.com), but if the computer is asleep, it doesn't work. IOPMSchedulePowerEvent() can wake the computer at a given time, but I had no existing Perl interface to it. I could have added it to a Mac:: module, but in this case, I didn't have the time, and I currently have no use for it other than this one script. Therefore, Inline.
One especially interesting thing about the code -- to me -- is that it uses the CFAbsoluteTime data type, which -- for reasons unknown to me -- is in seconds since January 1, 2001, GMT. So the C code keeps a constant to calculate the difference from perl's time().
#!/usr/local/bin/perl
# i use this to make sure my computer wakes up by 3 a.m. every morning,
# so my backups can run
# i run it from cron every 15 minutes (the computer is set to sleep
# after 15 minutes of inactivity)
# */15 * * * */Users/pudge/bin/wake.plx
# pudge@pobox.com 2004-04-01
use strict;
use warnings;
use Time::Local;
use Inline C => 'DATA',
LDDLFLAGS => '-bundle -flat_namespace -undefined suppress -framework Carbon',
INC => '-I/Developer/Headers/FlatCarbon';
my $now = time();
my @today = localtime($now);
@today[0, 1, 2] = (0, 55, 2);
my $then = timelocal(@today);
$then += 86400 if $now > $then;
schedule_event($then, 'wake');
__END__
__C__
#undef Move
#undef I_POLL
#undef DEBUG
#include <Carbon.h>
#include <mach/error.h>
// "type" defines here
// can be sleep, wake, shutdown, poweron, and wakepoweron
//#include <IOKit/pwr_mgt/IOPMKeys.h>
// difference between Unix epoch and CFAbsoluteTime epoch
#define EPOCH_DIFF 978307200
long schedule_event(long seconds_time_to_wake, const char * event_name)
{
CFDateRef time_to_wake;
CFStringRef type;
IOReturn io_error;
seconds_time_to_wake -= EPOCH_DIFF;
time_to_wake = CFDateCreate(kCFAllocatorDefault, (CFAbsoluteTime)seconds_time_to_wake);
type = CFStringCreateWithCString(kCFAllocatorDefault, event_name, NULL);
io_error = IOPMSchedulePowerEvent(time_to_wake, NULL, type);
CFRelease(time_to_wake);
CFRelease(type);
if (io_error != 0) {
printf("system: 0x%x, subsystem: 0x%x, code: 0x%x\n",
err_get_system(io_error),
err_get_sub(io_error),
err_get_code(io_error)
);
}
return io_error;
}
Missing something? (Score:1)
You can ask your computer to wakeup at 3:00 am and cron Backup.app to run at 3:15...
Best regards,
life is too short
Re:Missing something? (Score:2)
You should have looked harder :) (Score:1)
Re:You should have looked harder :) (Score:2)
Re:You should have looked harder :) (Score:1)
Re:You should have looked harder :) (Score:2)
Re:You should have looked harder :) (Score:1)
this was in my system log.
Apr 27 03:15:02 macjerry syslogd: restart
Apr 27 03:15:03 macjerry kernel: ApplePMUUserClient::setProperties AutoWake 0x00000000
Apr 27 03:15:03 macjerry kernel: ApplePMUUserClient::setProperties AutoPower 0x00000000
Apr 27 03:15:03 macjerry kernel: ApplePMUUserClient::setProperties AutoWake 0x00015123
Apr 27 03:15:03 macjerry osascript: LaunchApplication(/System/Library/CoreServices/System Events.app)
Apr 27 03:15:59 macjerry
Re:You should have looked harder :) (Score:2)
Re:You should have looked harder :) (Score:2)
Re:You should have looked harder :) (Score:1)
Re:You should have looked harder :) (Score:2)
Re:You should have looked harder :) (Score:1)
Let's try a photosensor looking at the screen, when activated
by the wakeup, cut current to electromagnet holding weight
above keyboard, yeah that ought to do the trick
I have not tried (at any time) system events, do you think
simulating a key press would do the trick?
Jerry
Re:You should have looked harder :) (Score:2)
Re:You should have looked harder :) (Score:1)
#include
main() {
UpdateSystemActivity(OverallAct);
return 0;
}
He said it "might" work.
I got my full fifteen minutes last night...
Jerry
Re:You should have looked harder :) (Score:1)
// cc -o keypress keypress.c -framework Carbon
#include <Carbon/Carbon.h>
main() {
UpdateSystemActivity(OverallAct);
return 0;
}
Jerry
Re:You should have looked harder :) (Score:2)
Re:You should have looked harder :) (Score:1)
protected screensaver, if a password is not entered in 90 seconds, the machine will go back to sleep.
Jerry
Re:You should have looked harder :) (Score:2)
But how do I get that entered when the machine wakes up?
Re:You should have looked harder :) (Score:1)
to my
which is in turn executed by periodic
/usr/bin/mail -s Crontab jerry <<DOC
Cron ran at `date`
`/usr/local/bin/dailyWakeup`
`/usr/local/bin/keypress`
DOC
dailyWak eup queues a request for the following night, the
keypress code evidently extends the session.
Tonight I am going to create a 400.mystuff file that simply
executes the
it into
Re:You should have looked harder :) (Score:2)
Re:You should have looked harder :) (Score:1)
have that much extra to do...
However I am starting to do weekly backups of some big
folders and that is why I am going to have a seperate file
containing code that will execute the keypress function and
have periodic execute this file just before any of the longer
jobs...Are we on the same page?
dailyWakeup queues an event that causes the system to wake
a little before cron fires.
cron fires and executes a script that contains the keypress function. (
Re:You should have looked harder :) (Score:2)
That's the part that concerns me. Last night, the machine wasn't even awake long enough for the clock in the GUI to update. I guess I can try setting them a minute apart and see what happens.
Re:You should have looked harder :) (Score:2)
Re:You should have looked harder :) (Score:1)
#!/bin/sh
/usr/local/bin/keypress
and dumped it into
/etc/periodic/{daily | weekly | daily} ( and made sure it is executable )
It fired first when cron started and I got my 15 minutes of fame.
http://homepage.mac.com/Cocoa for the whole story/package
Jerry
Re:You should have looked harder :) (Score:2)