MacOS – AppleScript working until placed in cron; causing Chrome to go unresponsive

applescriptcrongoogle-chromemacos

Good afternoon. Question: I have a simple apple script telling Google Chrome to open,
go to a URL, and enter presentation mode…

tell application "Google Chrome"
    activate
    make new window
    set myURL to "http://myURL.php"
    tell window 1 to make new tab with properties {URL:myURL}
    tell window 1 to enter presentation mode
end tell

Running in AppleScript editor, it behaves correctly. From CLI, it also behaves
correctly…

/usr/bin/osascript /<fqpn>/openURL.scpt

but if I take that snippet and put it in my cron, it fails to go to fullscreen and Chrome becomes unresponsive, requiring a force quit. I get the following error in /var/mail:

/<fqpn>/openURL.scpt:725:748: execution error: Google Chrome got an error: AppleEvent handler failed. (-10000)

I have no ~/.* files on this account (OSX 10.9.2), so I tried sourcing my /etc/profile first in my crontab, but no effect.

Any ideas what my problem is?

-Chris

Best Answer

Using the same applescript; I moved over to launchd; using a generic template pulled from

http://launched.zerowidth.com/

and everything behaved just as expected. I'm not sure what I was missing in my cron environment; but the answer seems to be to avoid crontabs for simple applescripts for now..