Launch Applescript on wakeup or sleep

Discussion in 'Mac Programming' started by mcmadhatter, Jun 21, 2007.

  1. mcmadhatter macrumors 6502

    mcmadhatter

    Joined:
    Sep 6, 2005
    Location:
    Bath, UK
    #1
    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
     
  2. gauchogolfer macrumors 603

    gauchogolfer

    Joined:
    Jan 28, 2005
    Location:
    American Riviera
    #2
    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.
     
  3. mkrishnan Moderator emeritus

    mkrishnan

    Joined:
    Jan 9, 2004
    Location:
    Grand Rapids, MI, USA
    #3
    What do you mean when you say sleepwatcher rarely works?
     
  4. mcmadhatter thread starter macrumors 6502

    mcmadhatter

    Joined:
    Sep 6, 2005
    Location:
    Bath, UK
    #4
    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
     
  5. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #5
    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/
     
  6. mkrishnan Moderator emeritus

    mkrishnan

    Joined:
    Jan 9, 2004
    Location:
    Grand Rapids, MI, USA
    #6
    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.
     
  7. mcmadhatter thread starter macrumors 6502

    mcmadhatter

    Joined:
    Sep 6, 2005
    Location:
    Bath, UK
    #7
    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 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?
     
  8. rothnd macrumors newbie

    Joined:
    Oct 22, 2008
    #8
    Help Please!!! Stuck like chuck!!

    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!
     

Share This Page