Hi everyone. I am trying to run an AppleScript via crontab on a schedule, each work day at 8:45 am. The script runs flawlessly from Script Debugger, however it fails when activated by cron and only runs up to opening Safari and logging into the correct website.
HELP! I don’t want to kick this off everyday on my own. I am open to suggestion if there is a better way to run this.
Here is all the stuff I think might be relevant:
System Preferences - Security & Privacy
I have cron added to Full Disk Access and Accessibility
I have tried to set this same thing up to run an AppleScript application - no joy.
The AppleScript runs fine when you run it manually.
The AppleScript runs when triggered by cron.
The AppleScript carries out some proportion of operations successfully when triggered by cron.
That would suggest that the issue is closely tied to whatever specific operation the script is trying to accomplish at that point … but we have no sight of that.
Now Apple deprecated the use of cron quite some time ago now (since version 10.4 by the looks of it)and recommend launchd instead. That may resolve your issue, of it may simply transfer it. There is also a launchd helper app available on the Mac app store if you wish to go that route.
Other tools, such as Keyboard Maestro, also allow you to schedule, and to be honest are a lot easier to use if you happen to have it available. I use this exclusively for script scheduling on my Mac, but do also use cron, at, etc. on other platforms.
I’m more of a bash guy but whenever I’ve needed to kick off jobs in cron and they’re finicky, the only solution I’ve come up with as a work around is to write out the progress made on each major milestone within the script into a file. I’d also suggest redirecting any error output to your same log file and review.
Redirection info: https://askubuntu.com/questions/625224/how-to-redirect-stderr-to-a-file (it’s for ubuntu but should work for macOS as well)
You can also try and kick off the script at different times so you can evaluate successful execution during the day (assuming it’s safe to execute multiple times).
I had a similar problem myself and just giving permission wan’t enough, but was happy to discover a solution. Also, giving the full path to osascript din’t work either BUT a prefix like this did it: