Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

NSAppleScriptMBS.DeterminePermissionToAutomateTarget(target as NSAppleEventDescriptorMBS, theAEEventClass as string = "****", theAEEventID as String = "****", askUserIfNeeded as boolean) as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
shared method Apple Script MBS MacCocoa Plugin 18.4 Yes No No Yes, macOS only No
Function: Determines whether the current application is able to send an AppleEvent with the given eventClass and eventID to the application described as target.
Example:
dim target as NSAppleEventDescriptorMBS = NSAppleEventDescriptorMBS.descriptorWithBundleIdentifier("com.apple.Safari")

// we ask for all apple events
dim e as integer = NSAppleScriptMBS.DeterminePermissionToAutomateTarget(target, "****", "****", true)

MsgBox str(e)
Notes:
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 (-1743) 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 false and permission has not been granted, then errAEEventWouldRequireUserConsent (-1744) will be returned.
The target must refer to an already running application.

If the current application is permitted to send the given AppleEvent to the target, then noErr (0) will be returned. If the current application is not permitted to send the event, errAEEventNotPermitted (-1743) will be returned. If the target application is not running, then procNotFound (-600) will be returned. If askUserIfNeeded is false, and this application is not yet permitted to send AppleEvents to the target, then errAEEventWouldRequireUserConsent (-1744) will be returned.

Mac OS X threading: Thread safe since version 10.14. Do not call this function on your main thread because it may take arbitrarily long to return if the user needs to be prompted for consent.

target: The address descriptor. Before calling AEDeterminePermissionToAutomateTarget, you set the descriptor to identify the target application for the Apple event. 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.
theAEEventClass: The event class of the Apple event to determine permission for.
theAEEventID: The event ID of the Apple event to determine permission for.
askUserIfNeeded: a Boolean; if true, and if this application does not yet have permission to send events to the target application, then prompt the user to obtain permission. If false, do not prompt the user.

Plugin returns -1 if the function is not available, e.g. older MacOS versions.

Feedback, Comments & Corrections

NSAppleScriptMBS.NSAppleScriptErrorAppName as string
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
shared method Apple Script MBS MacCocoa Plugin 11.2 Yes No No Yes, macOS only No
Function: One of the keys in the error dictionary.
Notes: Value for this key is a string that specifies the name of the application that generated the error.

Feedback, Comments & Corrections

NSAppleScriptMBS.NSAppleScriptErrorBriefMessage as string
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
shared method Apple Script MBS MacCocoa Plugin 11.2 Yes No No Yes, macOS only No
Function: One of the keys in the error dictionary.
Example:
dim source as string = "tell application ""iTunes"""+EndOfLine+"pause"+EndOfLine+"end if"
dim n as new NSAppleScriptMBS(source)

dim error as Dictionary
if not n.compile(error) then
// shows error about missing tell where it found an if.
MsgBox error.Value(n.NSAppleScriptErrorBriefMessage)
end if
Notes: Value for this key is a string that provides a brief description of the error.

Feedback, Comments & Corrections

NSAppleScriptMBS.NSAppleScriptErrorMessage as string
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
shared method Apple Script MBS MacCocoa Plugin 11.2 Yes No No Yes, macOS only No
Function: One of the keys in the error dictionary.
Example:
dim source as string = "tell application ""iTunes"""+EndOfLine+"pause"+EndOfLine+"end if"
dim n as new NSAppleScriptMBS(source)

dim error as Dictionary
if n.compile(error) then
MsgBox "OK"
else
// shows error about missing tell where it found an if.
MsgBox error.Value(n.NSAppleScriptErrorMessage)
end if
Notes: Value for this key is a NSRangeMBS object.

Feedback, Comments & Corrections

NSAppleScriptMBS.NSAppleScriptErrorNumber as string
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
shared method Apple Script MBS MacCocoa Plugin 11.2 Yes No No Yes, macOS only No
Function: One of the keys in the error dictionary.
Example:
dim source as string = "tell application ""iTunes"""+EndOfLine+"pause"+EndOfLine+"end if"
dim n as new NSAppleScriptMBS(source)

dim error as Dictionary
if not n.compile(error) then
// error about missing tell where it found an if.
MsgBox error.Value(n.NSAppleScriptErrorNumber) // shows -2741
end if
Notes: Value for this key is a number that specifies the error number.

Feedback, Comments & Corrections

NSAppleScriptMBS.NSAppleScriptErrorRange as string
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
shared method Apple Script MBS MacCocoa Plugin 11.2 Yes No No Yes, macOS only No
Function: One of the keys in the error dictionary.
Example:
dim source as string = "tell application ""iTunes"""+EndOfLine+"pause"+EndOfLine+"end if"
dim n as new NSAppleScriptMBS(source)

dim error as Dictionary
if not n.compile(error) then
// error about missing tell where it found an if.
dim r as NSRangeMBS = error.Value(n.NSAppleScriptErrorRange)
MsgBox r.String // {36,2}, the position of the if
end if
Notes: Value for this key is a string that supplies a detailed description of the error condition.

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS MacCocoa Plugin.




Links
MBS Xojo Chart Plugins