On Yosemite 10.10.5, I have an Apples Script application that runs and completes as desired under 2 of 3 conditions. The application is set to launch, by launchd plist 3 times per day at 7:05am, 3:05pm and 9:05pm.

  1. Completes - when run from Script Editor
  2. Completes - when running under launchd at 7:05am
  3. Applescript timeout warning - when running under launchd after ~7:21am and when the monitor is black

It may be important to the #2 success that the Energy Saver > Scheduled > Start up or wake = 7:00am, everyday. > Sleep = 11pm everyday. Also, Computer Sleep = Never and Display Sleep = 15 min.

The error message is Safari got an error: AppleEvent timed out. (-1712)

The 1st arrow below points to the line of code where timeout occurs. The hack is displayed at the 2nd arrow, allowing the script to 'gracefully' continue:

on waitForPageToLoad(repeatCount, myLogFile, theTabInUse)
    set interval to 1
    set currentCount to 0

    repeat repeatCount times
        set currentCount to currentCount + 1
        delay interval
            tell application "Safari"
-->             set docReady to do JavaScript "document.readyState" in theTabInUse
            end tell
        on error errstr
-->         display dialog "  waitForPageToLoad error: " & errstr giving up after 10
            set docReady to "complete"
        end try
    end repeat
end waitForPageToLoad

If I should wake up the screen within 2 minutes of the 1st arrow's code being sent, the script will continue fine.

Nothing related is in the Console system log. I am thinking this is a bug.

EDIT - I am trying to track down if the correct tab & window has been passed into the handler. It is possible the do JavaScript is not targeted correctly.

Does anyone have any ideas of how to troubleshoot or solve this?

  • @klanomath In essence, yes. (edited #3)
    – David C
    Sep 2, 2015 at 19:07
  • You may add some lines at the beginning like "tell application "System Events" tell process "Finder" keystroke return end tell end tell " or something similar to wake your monitor first.
    – klanomath
    Sep 2, 2015 at 19:18
  • Good idea. You suggestion does feel like a hack. It is interesting that line which times out is the 5th do JavaScript following make new document with properties {URL:"https:// ..."} of the script. I can't see why that would timeout and not the previous 4. The code above executes perfectly prior to these 4.
    – David C
    Sep 2, 2015 at 19:33
  • @klanomath The tell block did not work. The script still hangs on the do JavaScript line
    – David C
    Sep 2, 2015 at 21:44
  • May I just run the Apple Script in a VM or do I need any additional components, a special website/web-application or anything else?
    – klanomath
    Sep 2, 2015 at 21:57


You must log in to answer this question.

Browse other questions tagged .