AppleScript.DeterminePermissionToAutomateTarget
-----------------------------------------------

Checks whether AppleScript is allowed.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [AppleScript](component_AppleScript.md) | [9.0](newinversion90.md) | ✅ Yes | ❌ No | ❌ No | ❌ No | ❌ No |

MBS( "AppleScript.DeterminePermissionToAutomateTarget"; BundleID; AEEventClass; AEEventID { ; askUserIfNeeded } ) 

**MBS**( **"AppleScript.DeterminePermissionToAutomateTarget";** /\* Checks whether AppleScript is allowed. \*/  
**$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.e.g. "com.apple.Safari" \*/   
**$AEEventClass**; /\* The event class of the Apple event to determine permission for.  
\*\*\*\* for wildcard to use all.e.g. "\*\*\*\*" \*/   
**$AEEventID**; /\* The event ID of the Apple event to determine permission for.  
\*\*\*\* for wildcard to use all.e.g. "\*\*\*\*" \*/   
**$askUserIfNeeded**) /\* Optional; 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.e.g. 1 \*/ 

### 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](FilesLaunch.md)"; "/System/Library/CoreServices/System Events.app") \]   
Set Variable \[ $r ; Value: MBS ( "Applescript.DeterminePermissionToAutomateTarget"; "com.apple.systemevents"; "\*\*\*\*"; "\*\*\*\*"; 1) \]  
### See also

- [Files.Launch](FilesLaunch.md)

### Release notes

- **Version 9.0**
    - Added [Applescript.DeterminePermissionToAutomateTarget](http://www.mbsplugins.eu/ApplescriptDeterminePermissionToAutomateTarget.shtml) function.

### Blog Entries

- [Read and write notes in Contacts](https://www.mbsplugins.de/archive/2023-11-19/Read_and_write_notes_in_Contac/monkeybreadsoftware_blog_filemaker)
- [macOS Privacy and FileMaker](https://www.mbsplugins.de/archive/2020-08-11/macOS_Privacy_and_FileMaker/monkeybreadsoftware_blog_filemaker)
- [New MBS FileMaker Plugin 9.0](https://www.mbsplugins.de/archive/2019-01-22/New_MBS_FileMaker_Plugin_90/monkeybreadsoftware_blog_filemaker)
- [Neues MBS FileMaker Plugin 9.0](https://www.mbsplugins.de/archive/2019-01-22/Neues_MBS_FileMaker_Plugin_90/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 8.6pr4](https://www.mbsplugins.de/archive/2018-12-18/MBS_FileMaker_Plugin_version_8/monkeybreadsoftware_blog_filemaker)
- [Ask for permissions to control applications with AppleScript in FileMaker](https://www.mbsplugins.de/archive/2018-12-13/Ask_for_permissions_to_control/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

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

  
[AppleScript.Compile](AppleScriptCompile.md) - [AppleScript.Execute](AppleScriptExecute.md)

[HTML Version](ApplescriptDeterminePermissionToAutomateTarget.shtml)