Permanently grant right to control another app to Apple Script App

applescriptmail.app

I am using an AppleScript app (i.e., an AppleScript exported to an OS X app) to copy the message ID of an e-mail currently selected in Mail.app to the clipboard.

Whenever I run the AppleScript app, I have to confirm that it is allowed to read the message ID from Mail.app. That is, I get a popup asking:

“Get-E-Mail-Message-ID.app“ wants access to control “Mail.app“. Allowing control will provide access to documents and data in “Mail.app“, and to perform actions within that app.
This script needs to control other applications to run.

With two buttons, [Don't Allow] and [OK]. So I always have to click [OK].

Is it possible to permanently grant my app to read data from Mail.app?

I have already found System Preferences -> Security & Privacy -> Privacy, and checked the box under "Allow the apps below to control other apps.", but still get the popup whenever I run the AppleScript app.

Best Answer

A regular AppleScript saves properties and global variables (including variables in either run handler) in the script itself (the script file is modified). This is how persistent properties have been implemented, but now this can run into accessibility permissions issues, since modifying an application will cause the system to see it as a different one - one that hasn't been given permission.

The solution is to code sign your application (you can use a self-issued certificate) or make the scripts in the bundle run-only. You will lose persistent properties, but you can use some AppleScriptObjC to implement preferences via NSUserDefaults if you need to keep stuff between runs.