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 / Compiling Scripts


OSACompile

You can use the OSACompile function to compile the source data for a script and obtain a script ID for a compiled script or a script context.

FUNCTION OSACompile (scriptingComponent: ComponentInstance; 
                     sourceData: AEDesc; modeFlags: LongInt;
                     VAR previousAndResultingScriptID: OSAID)
                     : OSAError;
scriptingComponent
A component instance created by a prior call to the Component Manager function OpenDefaultComponent or OpenComponent (see page 10-4).
sourceData
A descriptor record containing suitable source data for the specified scripting component.
modeFlags
Information used by individual scripting components. To avoid setting mode flag values, specify kOSAModeNull. Other possible mode flags are listed in the description that follows.
previousAndResultingScriptID
The script ID for the resulting compiled script. If the value of this parameter on input is kOSANullScript, OSACompile returns a new script ID for the compiled script data. If the value of this parameter on input is an existing script ID, OSACompile updates the script ID so that it refers to the newly compiled script data.
DESCRIPTION
You can pass a descriptor record containing source data suitable for a specific scripting component (usually text) to the OSACompile function to obtain a script ID for the equivalent compiled script or script context. To compile the source data as a script context for use with OSAExecuteEvent or OSADoEvent, you must set the kOSACompileIntoContext flag, and the source data should include appropriate handlers.

After you have successfully compiled the script, you can use the returned script ID to refer to the compiled script when you call OSAExecute and other scripting component routines.

You can control the way a compiled script is executed by adding any of these flags to the modeFlags parameter:
FlagDescription
kOSAModePreventGetSourceCompiled script consists of only the minimum script data required to run the script. It will cause an error if passed to OSAGetSource.
kOSACompileIntoContextThe OSACompile function returns a script context instead of a compiled script.
kOSAModeAugmentContextScript data associated with script ID passed in previousAndResultingCompiledScriptID is augmented rather than replaced with the new compiled script. Specifying this flag automatically invokes the kOSAModeCompileIntoContext mode flag. If you redefine variables, handlers, and so on that were previously defined in the script context, the new definitions will replace the old ones.
kOSAModeNeverInteractAdds kAENeverInteract to sendMode parameter of AESend for events sent when script is executed.
kOSAModeCanInteractAdds kAECanInteract to sendMode parameter of AESend for events sent when script is executed.
kOSAModeAlwaysInteractAdds kAEAlwaysInteract to sendMode parameter of AESend for events sent when script is executed.
kOSAModeDontReconnectAdds kAEDontReconnect to sendMode parameter of AESend for events sent when script is executed.
kOSAModeCantSwitchLayerPrevents use of kAECanSwitchLayer in sendMode parameter of AESend for events sent when script is executed (the opposite of the Apple Event Manager's interpretation of the same bit).
kOSAModeDoRecordPrevents use of kAEDontRecord in sendMode parameter of AESend for events sent when script is executed (the opposite of the Apple Event Manager's interpretation of the same bit).

SPECIAL CONSIDERATIONS
If you use OSACompile with an instance of the generic scripting component and pass kOSANullScript in the previousAndResultingScriptID parameter, the generic scripting component uses the default scripting component to compile the script.

If you're recompiling a script, specify the original script ID in the previousAndResultingScriptID parameter. The generic scripting component uses the script ID to determine which scripting component it should use to compile the script.

RESULT CODES
noErr0No error
errOSACantCoerce-1700Source data incompatible with scripting component
errOSASystemError-1750General scripting system error
errOSAInvalidID-1751Invalid script ID
errOSAScriptError-1753Source data invalid (syntax error)
badComponentInstance$80008001Invalid component instance
SEE ALSO
For an example of the use of OSACompile to update an existing script ID, see Listing 10-5 on page 10-18. For an example of the use of OSACompile to obtain a new script ID, see Listing 10-2 on page 10-9.

For more information about the default scripting component associated with any instance of the generic scripting component, see "Generic Scripting Component Routines," which begins on page 10-83.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996