Important: The information in this document is obsolete and should not be used for new development.
Using Script Contexts to Handle Apple Events
The optional routines described in this section allow your application to use script contexts to handle Apple events. One way to do this is to install a general Apple event handler in your application's special handler dispatch table. The general Apple event handler provides initial handling for every Apple event received by your application. (For an example of such a handler, see "Using a Script Context to Handle an Apple Event" on page 10-19.)The general Apple event handler extracts the event's direct parameter, obtains a script ID for the script context associated with the object described in the direct parameter, and passes the Apple event and the script ID to either
OSAExecuteEvent
orOSADoEvent
. The main difference between these two functions is thatOSAExecuteEvent
returns a script ID for the resulting script value, whereasOSADoEvent
returns a reply Apple event that includes either the resulting script value or information about any errors that occurred.If the scripting component determines that a script context can't handle the specified event (for example, if an AppleScript script context doesn't include statements that handle the event),
OSAExecuteEvent
andOSADoEvent
returnerrAEEventNotHandled
. This causes the Apple Event Manager to look for an appropriate handler in the application's Apple event dispatch table or elsewhere, using standard Apple event dispatching. If the scripting component determines that a script context passed toOSAExecuteEvent
orOSADoEvent
can handle the event, the function attempts to use the script context for that purpose.Script contexts can in turn pass an event to a resume dispatch function with a statement that's equivalent to an AppleScript
continue
statement. TheOSASetResumeDispatchProc
andOSAGetResumeDispatchProc
functions allow your application to set and get pointers to the resume dispatch function used by a scripting component. These functions use the following type for a pointer to a resume dispatch function:
TYPE AEHandlerProcPtr = EventHandlerProcPtr;A resume dispatch function takes the same parameters as an Apple event handler and dispatches an event to an application's standard handler for that event.If you need to create a new, empty script context, you can use the
OSAMakeContext
function.A scripting component that supports the functions described in this section has the
kOSASupportsEventHandling
bit set in thecomponentFlags
field of its component description record.
Subtopics
- OSASetResumeDispatchProc
- OSAGetResumeDispatchProc
- OSAExecuteEvent
- OSADoEvent
- OSAMakeContext