AppleScript via crontab

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:

  1. 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.

  2. crontab
    45 8 * * 1-5 osascript /Applications/Scripts/thescript.scpt

If I understand correctly…

  1. The AppleScript runs fine when you run it manually.
  2. The AppleScript runs when triggered by cron.
  3. 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.

1 Like

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: (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).

Best of luck

I use cron on Linux, but on the Mac I find it infinitely easier to schedule automation via Keyboard Maestro.

On Linux, the cron problems I’ve had have usually been about needing to use full paths instead of relative paths.

Much better to use a launch daemon. Go with Lingon app. Works super well. Crons jobs are technically deprecated.

1 Like

Did you solve the problem?

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:

45 8 * * 1-5 /usr/bin/bash; osascript /Applications/Scripts/thescript.scpt

1 Like