Important: The information in this document is obsolete and should not be used for new development.
OSAExecuteEvent
You can use theOSAExecuteEvent
function to handle an Apple event with the aid of a script context and obtain a script ID for the resulting script value.
FUNCTION OSAExecuteEvent(scriptingComponent: ComponentInstance; theAppleEvent: AppleEvent; contextID: OSAID; modeFlags: LongInt; VAR resultingScriptValueID: OSAID) : OSAError;
scriptingComponent
- A component instance created by a prior call to the Component Manager function
OpenDefaultComponent
orOpenComponent
(see page 10-4).theAppleEvent
- The Apple event to be handled.
contextID
- The script ID for the script context to be used to handle the Apple event.
modeFlags
- Information used by individual scripting components. To avoid setting any mode flags, specify
kOSAModeNull
. Other possible mode flags are listed in the description that follows.resultingScriptValueID
- A script ID for the resulting script value.
DESCRIPTION
TheOSAExecuteEvent
function attempts to use the script context specified by thecontextID
parameter to handle the Apple event specified by thetheAppleEvent
parameter. If the scripting component determines that the script context can't handle the event (for example, if a script written in AppleScript doesn't include statements that handle the event),OSAExecuteEvent
immediately returnserrAEEventNotHandled
rather thanerrOSAScriptError
.If the scripting component determines that the script context can handle the event,
OSAExecuteEvent
executes the script context's handler and returns the resulting script ID. If execution of the script context's handler for the event generates an error,OSAExecuteEvent
returnserrOSAScriptError
, and you can get more detailed error information by calling theOSAScriptError
function.You can control the way in which the scripting component executes a script context by adding any of these flags to the
modeFlags
parameter:
Flag Description kOSAModeNeverInteract Adds kAENeverInteract
tosendMode
parameter ofAESend
for events sent when script is executed.kOSAModeCanInteract Adds kAECanInteract
tosendMode
parameter ofAESend
for events sent when script is executed.kOSAModeAlwaysInteract Adds kAEAlwaysInteract
tosendMode
parameter ofAESend
for events sent when script is executed.kOSAModeCantSwitchLayer Prevents use of kAECanSwitchLayer
insendMode
parameter ofAESend
for events sent when script is executed (the opposite of the Apple Event Manager's interpretation of the same bit).kOSAModeDontReconnect Adds kAEDontReconnect
tosendMode
parameter ofAESend
for events sent when script is executed.kOSAModeDoRecord Prevents use of kAEDontRecord
insendMode
parameter ofAESend
for events sent when script is executed (the opposite of the Apple Event Manager's interpretation of the same bit).If the script context identified by the
contextID
parameter specifies that the Apple event should be passed to the application's default handler for that event (for example, with an AppleScriptcontinue
statement),OSAExecuteEvent
passes the event to the resume dispatch function currently being used by the scripting component. The resume dispatch function dispatches the event directly to the application's standard handler for that event (that is, without callingOSAExecuteEvent
again). If thecontextID
parameter iskOSANullScript
, theOSAExecuteEvent
function passes the event directly to the resume dispatch function. If a call to the resume dispatch function is successful, execution of the script context proceeds from the point at which the resume dispatch function was called.
- IMPORTANT
- The
OSAExecuteEvent
function can generate the result codeerrAEEventNotHandled
in at least two ways. If the scripting component determines that a script context doesn't declare a handler for a particular event,OSAExecuteEvent
immediately returnserrAEEventNotHandled
. If a scripting component calls its resume dispatch function during script execution and the application's standard handler for the event fails to handle it,OSAExecuteEvent
returnserrOSAScriptError
and a call toOSAScriptError
withkOSAErrorNumber
in theselector
parameter returnserrAEEventNotHandled
as the resulting error description.RESULT CODES