Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

AppleScript.DeterminePermissionToAutomateTarget

Checks whether AppleScript is allowed.

Component Version macOS Windows Linux Server iOS SDK
AppleScript 9.0 ✅ Yes ❌ No ❌ No ❌ No ❌ No
MBS( "AppleScript.DeterminePermissionToAutomateTarget"; BundleID; AEEventClass; AEEventID { ; askUserIfNeeded } )   More

Parameters

Parameter Description Example Flags
BundleID The bundle ID of the application to control.

The target address descriptor must refer to a running application. If the target application is on another machine, then Remote AppleEvents must be enabled on that machine for the user.
"com.apple.Safari"
AEEventClass The event class of the Apple event to determine permission for.
**** for wildcard to use all.
"****"
AEEventID The event ID of the Apple event to determine permission for.
**** for wildcard to use all.
"****"
askUserIfNeeded Whether dialog can show to ask user if needed.
Pass 1 to allow dialog or 0 to disallow.

If 1, and if this application does not yet have permission to send events to the target application, then prompt the user to obtain permission. If 0, do not prompt the user.
Default is 0.
1 Optional

Result

Returns OK, ApplicationNotRunning, NotPermitted, WouldRequireUserConsent, or error.

Description

Checks whether AppleScript is allowed.
Determines whether the current application is able to send an AppleEvent with the given eventClass and eventID to the application described as target via bundle ID.

Mac OS 10.14 and later impose additional requirements on applications when they send AppleEvents to other applications in order to insure that users are aware of and consent to allowing such control or information exchange. Generally this involves the user being prompted in a secure fashion the first time an application attempts to send an AppleEvent to another application. If the user consents then this application can send events to the target. If the user does not consent then any future attempts to send AppleEvents will result in a failure with errAEEventNotPermitted being returned.

Certain AppleEvents are allowed to be sent without prompting the user. Pass typeWildCard (****) for the eventClass and eventID to determine if every event is allowed to be sent from this application to the target.

Applications can determine, without sending an AppleEvent to a target application, whether they are allowed to send AppleEvents to the target with this function. If askUserIfNeeded is true, and this application does not yet have permission to send AppleEvents to the target, then the user will be asked if permission can be granted; if askUserIfNeeded is 0 and permission has not been granted, then WouldRequireUserConsent will be returned.

The target bundle ID must refer to an already running application.

If the current application is permitted to send the given AppleEvent to the target, then OK will be returned. If the
current application is not permitted to send the event, NotPermitted will be returned. If the target application
is not running, then ApplicationNotRunning will be returned. If askUserIfNeeded is false, and this application is not yet permitted
to send AppleEvents to the target, then WouldRequireUserConsent will be returned.

Requires MacOS 10.14 or newer.

May not work in FileMaker 18 due to missing entitlements for the FileMaker app. You can try FileMaker 17 instead, where it works. Or run FileMaker 18 from Terminal, where it also works.

Examples

Ask for permissions for Safari:

MBS( "Applescript.DeterminePermissionToAutomateTarget"; "com.apple.Safari"; "****"; "****"; 1 )

Ask for permissions for Finder:

MBS( "Applescript.DeterminePermissionToAutomateTarget"; "com.apple.Finder"; "****"; "****"; 1 )

Ask for permissions for Mail:

MBS( "Applescript.DeterminePermissionToAutomateTarget"; "com.apple.Mail"; "****"; "****"; 1 )

Ask for permissions for System Events:

Set Variable [ $r ; Value: MBS("Files.Launch"; "/System/Library/CoreServices/System Events.app") ]
Set Variable [ $r ; Value: MBS( "Applescript.DeterminePermissionToAutomateTarget"; "com.apple.systemevents"; "****"; "****"; 1) ]

See also

Release notes

Blog Entries

This function checks for a license.

Created 13th December 2018, last changed 21st March 2024


AppleScript.Compile - AppleScript.Execute