PDA

View Full Version : Launch Applescript on wakeup or sleep




mcmadhatter
Jun 21, 2007, 10:07 AM
does anyone know of a tool/way of launching an applescript on sleep or wakeup? I have tried sleepwatcher but it rarely works, so I am looking for an alternative



gauchogolfer
Jun 21, 2007, 10:17 AM
does anyone know of a tool/way of launching an applescript on sleep or wakeup? I have tried sleepwatcher but it rarely works, so I am looking for an alternative

Do you want something that is regularly scheduled, or just each time you wake/sleep? If you are on a schedule, you can use iCal to run Applescripts.

mkrishnan
Jun 21, 2007, 10:31 AM
What do you mean when you say sleepwatcher rarely works?

mcmadhatter
Jun 21, 2007, 11:00 AM
Each time I wake or sleep

sleepwatcher executes a script maybe 1 time in 10

basically sleepwatcher is set to execute the scirpt toUpon.wakeup and all the script contains is

#!/bin/sh
osascript /Users/Jeffrey/Library/Scripts/toUpon.scpt

wrldwzrd89
Jun 21, 2007, 11:09 AM
I don't know if Lingon is capable of this task, but it should be, given that launchd, the engine behind Lingon, does support launch-on-wake.

http://lingon.sourceforge.net/

mkrishnan
Jun 21, 2007, 11:12 AM
What does console.log say about sleepwatcher on the times when the script fails to execute? Lingon soudns very interesting, but I wonder if the problem that affects sleepwatcher will affect it too.

mcmadhatter
Jun 21, 2007, 11:20 AM
SystemUIServer[1131] Error: Unable to get extended status

I think that is coming from the script, is there a way to put something in in the #!/bin/sh to print something to console.log? then I can check whether it is a problem with a script or sleepwatcher.

Lingon has only has options for doing it at login, I don't think that will fire when the laptop is woken up. I'll have a look now to see what launchd can do.

Here is a list (http://developer.apple.com/DOCUMENTATION/Darwin/Reference/ManPages/man5/launchd.plist.5.html) of the options of launchd, i.

StartInterval <integer>
This optional key causes the job to be started every N seconds. If the
system is asleep, the job will be started the next time the computer
wakes up. If multiple intervals transpire before the computer is woken,
those events will be coalesced into one event upon wake from sleep.

is there a way to tell it to stop after a single execution?

rothnd
Oct 22, 2008, 03:34 AM
Hey all

I'm hoping someone out there has learned something useful about launchd, plist's, and timing scripts.

I have a rather simple script that I was trying to make run on a schedule through launchd (15 min to be exact) mainly to get to learn the system.

I'll have to post the code later since I'm currently on a Win comp at work and it won't read the scpt file.

Anyway, the problems... I finally got through it all enough to load the script into launchd through a valid plist ("verified in Lingon" though I don't think was necessary since all Lingon did was add fields withe "false" values). The jist though is the plist file (I've named com.nathan.messagealert.plist to keep the *^#4& formatting going) calls on an Applescript (which runs perfectly fine in the editor or even as an app on startup) which it should then run on a "StartInterval" schedule of 900 sec. Now, I read and found the proper way of making the script an executable file which made it load but it's acting very funny. Remember the time schedule of 15 min I mentioned?? Well, when the script was loaded it kept running and running and running...you get the idea. It wouldn't stop until I killed it.

Any thoughts on why this would react this way? Is a scpt file ok? Does the scpt need a "quit" or "exit" at the end of it? I'm just analyzing the possibilities...

Anyway, I'll post the code when I get home. I'd appreciate anything!