Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Interapplication Communication /
Chapter 10 - Scripting Components / Scripting Components Reference
Optional Scripting Component Routines


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 or OSADoEvent. The main difference between these two functions is that OSAExecuteEvent returns a script ID for the resulting script value, whereas OSADoEvent 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 and OSADoEvent return errAEEventNotHandled. 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 to OSAExecuteEvent or OSADoEvent 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. The OSASetResumeDispatchProc and OSAGetResumeDispatchProc 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 the componentFlags field of its component description record.


Subtopics
OSASetResumeDispatchProc
OSAGetResumeDispatchProc
OSAExecuteEvent
OSADoEvent
OSAMakeContext

Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996