Problems executing an osascript command via cron

applescriptbashcronremindersterminal

I have a little shell script which creates a new reminder for a project. This works pretty fine and I can execute in the command line newCfSamples "my new sample" and the reminder gets created.

I now have a little R script, which figures out what samples are new and it should create a reminder for this. This script works fine as well and creates the Reminders.

Both together, so cron is starting my R script fails at the point when it is executing my little newCfSamples script with the following error message: execution error: Reminders got an error: An error of type -1743 has occurred. (-1743).

I then started my script directly with cron and this also fails. Here is the complete error message.

Subject: Cron <madejung@madejung-2> /Users/madejung/bin/newCfSamples test
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=madejung>
X-Cron-Env: <USER=madejung>
X-Cron-Env: <HOME=/Users/madejung>
Date: Wed, 14 Sep 2016 15:42:00 +0200 (CEST)

290:540: execution error: Reminders got an error: An error of type -1743 has occurred. (-1743)

Would be great if somebody would help me get this running.

My newCfSamples script looks like this:

#!/usr/bin/env bash                                                                                                               
# Make a new reminder via terminal script                                                                                         
# args: remind <title> <date> <time>                                                                                                                                                                                 
my_date=`date "+%d/%m/%Y"`
my_time='09:00'
osascript - "$1" "${my_date}" "${my_time}" <<END                                                                                                        
on run argv                                                                                                                       
    set stringedAll to date (item 2 of argv & " " & item 3 of argv)                                                               
    tell application "Reminders"                                                                                                  
        make new reminder in list "CF User Sample" with properties {name:item 1 of argv, due date:stringedAll}                                             
    end tell                                                                                                                      
end run                                                                                                                           
END

Best Answer

I think I found the solution. As I mentioned in the above comments, I am using the GUI LaunchControl, I started the job once by hand with the menu Job -> Start and I got a little popup if R is allowed to access Reminders. I clicked yes and now it is working.

It looks like, this popup couldn't be displayed so I could never allow it.

This is how the LaunchControl entry looks like