3 Replies Latest reply: Oct 20, 2008 12:01 PM by Camelot
Tevis Money Level 2 Level 2 (255 points)
So I have a script, which checks to see if an application is running, sleeps for a few minutes and then checks again before continuing it's program. For the sleep, I'm using

"do shell script 'sleep 300'"

If I set the sleep value for anything less than 300 (5 minutes) the scrip executes flawlessly every time. If I set the sleep value for 5 minutes (my ideal value) it errors out. What's weird is that if I put in some dialog box displays at various checkpoints after the sleep, it executes without problem. Is there something important about 5 minute intervals in AppleScript that would be causing this?

MBP, Mac OS X (10.5.5), Powerbook (Nov. 02)
  • 1. Re: Applescript errors after sleeping for 5 minutes
    Camelot Level 8 Level 8 (45,790 points)
    What's wrong is that you're going about this the wrong way.

    Since you're using do shell script, AppleScript is waiting for a response from the shell. By default every action has a timeout value (so that AppleScript doesn't sit and wait indefinitely for something that's broken). That's what the 5 minutes indicates - up to 5 minutes and you're fine, but after 5 minutes AppleScript is giving up, assuming that the shell command failed.

    There are two solutions - one is to change the timeout value, but the better solution is to use AppleScript's sleep rather than call a shell script:

    delay 300


    Note that you can also use AppleScript date math as well:

    delay (5 * minutes)
  • 2. Re: Applescript errors after sleeping for 5 minutes
    Tevis Money Level 2 Level 2 (255 points)
    I knew that AppleScript had a delay, but for some reason I recall the delay function causing applescript to either eat a lot of processor time or hang the cursor while it was waiting, which was why I was using sleep instead. Is this no longer the case?
  • 3. Re: Applescript errors after sleeping for 5 minutes
    Camelot Level 8 Level 8 (45,790 points)
    Is this no longer the case?


    No. That was fixed a long time ago.