Script App Can't Access Reminders.app without Permission

Hello,

I’m not new to the forum, but I forgot what my old account was and have just lurked for years.

I’ve got a problem with an apple script app that calls Reminders. It’s a simple script that creates two different reminders at random times. Whenever the script runs every three hours, it prompts for permission:

““Random Reminder.app” would like to access your reminders.”
It has the choices “Don’t Allow” or “OK”.

If I am away, the script sits there waiting, then times out:

“AppleEvent timed out. Reminders got an error: AppleEvent timed out. (-1712)”

This is a problem since I need the script to run without my input. FYI the script executes just fine when loaded into AppleScript Editor. The problem is with any script that is an app.

I found a solution here once. Adding the script app to System Preferences>Security & Privacy>Privacy let the script work without issue until this past fall. My suspicion is that something changed in Sierra or High Sierra (I didn’t upgrade to either until this past fall). Fantasictal.app accesses Reminders just fine, but not my script app. I’m not sure how to fix this. Got any suggestions?

Model: Mac mini (Late 2014),
AppleScript: 2.7
Browser: Safari 605.1.15
Operating System: Mac OS X (10.13 Public Beta)

Hi. Welcome (back) to MacScripter.

Is your script app running as a stay-open application with an ‘idle’ handler?
Does it use any properties or global variables?

I’ve been fooling with this in 10.13.4 this morning and am finding that my test script (a stay-open application with an ‘idle’ handler which creates a new reminder every five minutes) only needs its access to Reminders to be OK’d the very first time it’s run. However, if something happens to modify the script file — such as me editing the code and saving the changes, or the script itself having properties or globals (whose values are saved back into the file whenever the script app quits) — access has to be OK’d again next time the app’s run.

Great questions. Thanks for replying.

My script app isn’t running as a stay-open application with an ‘idle’ handler. Nor does it use any global variables. What do you mean by properties? I have variables set that are used in the script. I.E. “set _date to (current date) + ((TimeX + TimeYwhimey) * 0.33 * hours)”. I have a set array of text choices for a reminder that are randomly selected.

I call Reminders this way:
tell application “Reminders”
tell list listName
set newReminder to make new reminder with properties {name:_name, body:_body, remind me date:_enddate}
end tell
end tell

I believe this is a OS problem, not an Apple scripting problem. I might have to do something similar to what you’re doing. Each time the app is run, it needs to be authorized. Your workaround is to have the app stay idle, thus only needing one permission event per launch. My app runs, adds a remind to Reminders, then exits. Every time it runs, it requires me to grant permission.

I’d still like to return to how things were before where adding the script into the System Preferences>Security & Privacy>Privacy>Reminders pane would let the script run without notice every time.

If my theory’s correct — and I can’t know for sure without seeing your script or knowing how it’s being run every three hours — the values of some or all of the variables are being saved back into the script file each time the script finishes running. This is perfectly normal with properties, globals, and “run handler” variables. However, the next time the script app’s run, it’s in a different state from when it was given permission to access your Reminders, so macOS’s security system queries it.

The way to prevent the file being modified would be to use only local variables. These values aren’t saved. A convenient way to do this would be to put the script code (or the run handler part of it) into an ordinary handler, like this:

doTheBusiness() -- Or whatever you want to call the handler below.

on doTheBusiness()
	
	-- Script code here. All variables used will be local unless explicitly declared otherwise.
	
end doTheBusiness

But do post your script if you want any help doing this.