| Framework | Carbon/Carbon.h |
| Declared in | ASDebugging.h ASRegistry.h AppleScript.h OSA.h OSAComp.h OSAGeneric.h |
The Open Scripting Architecture (OSA) provides a standard and extensible mechanism for interapplication communication in Mac OS X. It provides support for creating scriptable applications and for writing scripting components to implement scripting languages. Every Mac OS X system includes the AppleScript component, which implements AppleScript, the standard scripting language defined by Apple. However, developers can write scripting components for additional scripting languages. For conceptual information on the OSA, see “Open Scripting Architecture” in AppleScript Overview.
You need to use this reference if you are writing a scripting component or if your application needs to interact with scripting components to manipulate and execute scripts. The API described in this document is implemented by the OpenScripting framework, a subframework of the Carbon framework. For information about working with components, see Scripting Components in Inside Macintosh: Interapplication Communication.
Important: Do not rely on the API descriptions in Interapplication Communication—Open Scripting Architecture Reference provides the current API documentation.
The Apple Event Manager, another part of the OSA, is implemented primarily by the AE framework, a subframework of the Application Services framework, and is documented in Apple Event Manager Reference and Apple Events Programming Guide. Applications use the Apple Event Manager to send and respond to Apple events and to make their operations and data available to AppleScript scripts.
To execute a script, your application must first obtain a valid script ID for a compiled script or script context. You can use either the OSALoad function or the optional OSACompile function to obtain a script ID.
Scripting components can provide three optional functions that get the name of a scripting component, compile a script, and update a script ID. A scripting component that supports the functions in this section has the kOSASupportsCompiling bit set in the componentFlags field of its component description record.
Scripting components can provide support for two optional functions which coerce data in a descriptor record to a script value and coerce a script value to data in a descriptor record. A scripting component that supports the functions in this section has the kOSASupportsAECoercion bit set in the componentFlags field of its component description record.
Some scripting components provide functions that allow your application to set or get pointers to the create and send functions used by the scripting component when it sends and creates Apple events during script execution. If you do not set the pointers that specify these functions, the scripting component uses the standard AECreateAppleEvent and AESend functions with default parameters. A scripting component that supports the functions described in this section has the kOSASupportsAESending bit set in the componentFlags field of its component description record.
Script editors use these functions to allow users to control recording. Any application can use these functions to provide its own script-recording interface. A scripting component that supports the functions described in this section has the kOSASupportsRecording bit set in the componentFlags field of its component description record.
You can use these functions if you know that the script data to be executed will be executed only once. A scripting component that supports the functions described in this section has the kOSASupportsConvenience bit set in the componentFlags field of its component description record.
Scripting components that provide several dialects may provide five functions that allow you to switch between dialects dynamically and get information about currently available dialects. The codes for specific dialects are provided by the scripting component. A scripting component that supports the functions described in this section has the kOSASupportsDialects bit set in the componentFlags field of its component description record.
OSASetCurrentDialect
OSAGetCurrentDialect
OSAAvailableDialectCodeList
OSAGetDialectInfo
OSAAvailableDialects
The optional functions 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. 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.
The default scripting component for any instance of the generic scripting component is initially AppleScript, but you can change it if necessary.
You can’t use the generic scripting component to call a component-specific routine. Instead, you must use an instance of the specific scripting component that supports the routine.
To facilitate the use of component-specific routines, the generic scripting component allows you to identify the scripting component that created stored script data, get an instance of a specified scripting component, and convert between generic script IDs and component-specific script IDs.
All scripting components must use the OSAGetStorageType, OSAAddStorageType, and OSARemoveStorageType functions described in this section to add, remove, and inspect the trailers appended to script data in generic storage descriptor records.
ASGetAppTerminology
ASGetHandler
ASGetProperty
ASSetHandler
ASSetProperty
OSAGetHandler
OSAGetHandlerNames
OSAGetProperty
OSAGetPropertyNames
OSAGetSysTerminology
OSASetHandler
OSASetProperty
OSAGetAppTerminology Deprecated in Mac OS X v10.5
NewOSAActiveUPP
NewOSACreateAppleEventUPP
NewOSASendUPP
DisposeOSAActiveUPP
DisposeOSACreateAppleEventUPP
DisposeOSASendUPP
InvokeOSAActiveUPP
InvokeOSACreateAppleEventUPP
InvokeOSASendUPP
Warning: Do not use the OSA debugging functions listed here. They were were not intended for public use, they do not work, and they will return an error.
OSADebuggerCreateSession
OSADebuggerDisposeCallFrame
OSADebuggerDisposeSession
OSADebuggerGetBreakpoint
OSADebuggerGetCallFrameState
OSADebuggerGetCurrentCallFrame
OSADebuggerGetDefaultBreakpoint
OSADebuggerGetPreviousCallFrame
OSADebuggerGetSessionState
OSADebuggerGetStatementRanges
OSADebuggerGetVariable
OSADebuggerSessionStep
OSADebuggerSetBreakpoint
OSADebuggerSetVariable
ASGetSourceStyles Deprecated in Mac OS X v10.5
ASSetSourceStyles Deprecated in Mac OS X v10.5
Gets the current text style attributes AppleScript uses to display script text.
OSAError ASCopySourceAttributes ( ComponentInstance scriptingComponent, CFArrayRef *resultingSourceAttributes );
A component instance created by a prior call to the Component Manager function OpenDefaultComponent or OpenComponent.
If successful, returns a reference to an array (of type CFArray) of dictionaries (of type CFDictionary) of text style attributes; otherwise, returns nil.
The order of elements in the array corresponds to the constants defined in “Source Style Constants,” and therefore also to the names returned by ASGetSourceStyleNames. For example, the first dictionary in the array (at position kASSourceStyleUncompiledText) describes the style for uncompiled text. However, you should not rely on there being any specific number of dictionaries in the returned array—instead, count the number of items in the array before accessing any of them.
This array is a copy and the caller is responsible for releasing it, according to the rules described in Ownership Policy in Memory Management Programming Guide for Core Foundation.
A result code. See “Result Codes.”
A text style attribute is typically something that is meaningful to a CFAttributedString, such as the one returned by OSACopyDisplayString or OSACopySourceString. However, clients may add other attributes using ASSetSourceAttributes.
AppleScript.hDeprecated. Use OSAGetAppTerminology instead.
OSAError ASGetAppTerminology ( ComponentInstance scriptingComponent, FSSpec *fileSpec, short terminologID, Boolean *didLaunch, AEDesc *terminologyList );
A result code. See “Result Codes.”
Provided for backward compatibility only. Use OSAGetAppTerminology instead.
ASDebugging.h
Deprecated. Use OSAGetHandler instead.
OSAError ASGetHandler ( ComponentInstance scriptingComponent, OSAID contextID, const AEDesc *handlerName, OSAID *resultingCompiledScriptID );
A result code. See “Result Codes.”
Provided for backward compatibility only. Use OSAGetHandler instead.
ASDebugging.h
Deprecated. Use OSAGetProperty instead.
OSAError ASGetProperty ( ComponentInstance scriptingComponent, OSAID contextID, const AEDesc *variableName, OSAID *resultingScriptValueID );
A result code. See “Result Codes.”
Provided for backward compatibility only. Use OSAGetProperty instead.
ASDebugging.hObtains a list of style names that are each formatted according to the script format styles currently used by the AppleScript component.
OSAError ASGetSourceStyleNames ( ComponentInstance scriptingComponent, SInt32 modeFlags, AEDescList *resultingSourceStyleNamesList );
A component instance created by a prior call to the Component Manager function OpenDefaultComponent or OpenComponent.
Reserved for future use. Set to kOSAModeNull.
A pointer to a list of style names (for example, “Uncompiled Text,” “Normal Text”) that are each formatted according to the current script format styles. The order of the names corresponds to the order of the source style constants listed in “Source Style Constants.” For example, the first name in the list (at position kASSourceStyleUncompiledText) is formatted according to the style for uncompiled text.
A result code. See “Result Codes.”
AppleScript.h
Initializes the AppleScript component.
OSAError ASInit ( ComponentInstance scriptingComponent, SInt32 modeFlags, UInt32 minStackSize, UInt32 preferredStackSize, UInt32 maxStackSize, UInt32 minHeapSize, UInt32 preferredHeapSize, UInt32 maxHeapSize );
A component instance created by a prior call to the Component Manager function OpenDefaultComponent or OpenComponent.
Reserved for future use. Set to kOSAModeNull.
The minimum size for the portion of the application’s heap used by the AppleScript component’s application-specific stack.
The preferred size for the portion of the application’s heap used by the AppleScript component’s application-specific stack.
The maximum size for the portion of the application’s heap used by the AppleScript component’s application-specific stack.
The minimum size for the portion of the application’s heap used by the AppleScript component’s application-specific heap. (See Version Notes section.)
The preferred size for the portion of the application’s heap used by the AppleScript component’s application-specific heap. (See Version Notes section.)
The maximum size for the portion of the application’s heap used by the AppleScript component’s application-specific heap. (See Version Notes section.)
A result code. See “Result Codes.”
Your application should set the modeFlags parameter to kOSAModeNull. You can use the other parameters to specify memory sizes for the portion of your application’s heap used by the AppleScript component for its application-specific heap and stack. If your application sets any of these parameters to 0, the AppleScript component uses the corresponding value in your application’s 'scsz' resource. If that value is also set to 0, the AppleScript component uses the default values described in “Default Initialization Values.”
If your application doesn’t call ASInit explicitly, the AppleScript component initializes itself using the values specified in your application’s 'scsz' resource when your application first calls any scripting component routine. If any of these values are set to 0, the AppleScript component uses the corresponding default value.
If your application doesn’t call ASInit explicitly and doesn’t call any scripting component routines, the AppleScript component will not be initialized. For example, if your application opens and closes the AppleScript component or calls Component Manager functions such as OpenDefaultComponent or FindNextComponent but doesn’t call any scripting component routines, the AppleScript component is not initialized.
When the AppleScript component is initialized, it uses your application’s high memory to create the blocks that it locks for its own use. If you expect to lock any portion of high memory for a shorter time than you expect the AppleScript component to be available, you should call ASInit explicitly.
Starting in Mac OS X version 10.5, heap size parameter values are ignored—AppleScript's heap will grow as large as needed.
AppleScript.h
Deprecated. Use OSASetHandler instead.
OSAError ASSetHandler ( ComponentInstance scriptingComponent, OSAID contextID, const AEDesc *handlerName, OSAID compiledScriptID );
A result code. See “Result Codes.”
Provided for backward compatibility only. Use OSASetHandler instead.
ASDebugging.h
Deprecated. Use OSASetProperty instead.
OSAError ASSetProperty ( ComponentInstance scriptingComponent, OSAID contextID, const AEDesc *variableName, OSAID scriptValueID );
A result code. See “Result Codes.”
Provided for backward compatibility only. Use OSASetProperty instead.
ASDebugging.hSets the text style attributes used by the AppleScript component to display scripts.
OSAError ASSetSourceAttributes ( ComponentInstance scriptingComponent, CFArrayRef sourceAttributes );
A component instance created by a prior call to the Component Manager function OpenDefaultComponent or OpenComponent.
A reference to an array (of type CFArray) of dictionaries (of type CFDictionary) of text style attributes.
You can pass a nil reference for this parameter if you want the AppleScript component to display script text using its default styles.
A result code. See “Result Codes.”
A text style attribute is typically something that is meaningful to a CFAttributedString, such as the one returned by OSACopyDisplayString or OSACopySourceString. However, clients may add any attributes they like. Because of this, you should generally call ASSetSourceAttributes with a modified copy of the result from ASCopySourceAttributes, not a built-from-scratch set of attributes.
The order of elements in the array should correspond to the constants defined in “Source Style Constants,” and therefore also to the names returned by ASGetSourceStyleNames. After calling ASSetSourceAttributes, you must dispose of the style element array you used to specify the text style attributes.
AppleScript.hDisposes of a universal procedure pointer to an application-defined active function.
void DisposeOSAActiveUPP ( OSAActiveUPP userUPP );
The UPP to dispose of.
OSA.hDisposes of a universal procedure pointer to an application-defined Apple event create function.
void DisposeOSACreateAppleEventUPP ( OSACreateAppleEventUPP userUPP );
The UPP to dispose of.
OSA.hDisposes of a universal procedure pointer to an application-defined send function.
void DisposeOSASendUPP ( OSASendUPP userUPP );
The UPP to dispose of.
OSA.hInvokes an application-defined active function.
OSErr InvokeOSAActiveUPP ( SRefCon refCon, OSAActiveUPP userUPP );
A result code. See “Result Codes.”
OSA.hInvokes an application-defined Apple event creation function.
OSErr InvokeOSACreateAppleEventUPP ( AEEventClass theAEEventClass, AEEventID theAEEventID, const AEAddressDesc *target, short returnID, SInt32 transactionID, AppleEvent *result, SRefCon refCon, OSACreateAppleEventUPP userUPP );
A result code. See “Result Codes.”
OSA.hInvokes an application-defined send function.
OSErr InvokeOSASendUPP ( const AppleEvent *theAppleEvent, AppleEvent *reply, AESendMode sendMode, AESendPriority sendPriority, SInt32 timeOutInTicks, AEIdleUPP idleProc, AEFilterUPP filterProc, SRefCon refCon, OSASendUPP userUPP );
A result code. See “Result Codes.”
OSA.hCreates a new universal procedure pointer to an application-defined active function.
OSAActiveUPP NewOSAActiveUPP ( OSAActiveProcPtr userRoutine );
A pointer to the active function.
The new UPP.
OSA.hCreates a new universal procedure pointer to an application-defined Apple event creation function.
OSACreateAppleEventUPP NewOSACreateAppleEventUPP ( OSACreateAppleEventProcPtr userRoutine );
A pointer to the creation function.
The new UPP.
OSA.h
Creates a new universal procedure pointer to an application-defined send function.
OSASendUPP NewOSASendUPP ( OSASendProcPtr userRoutine );
A pointer to the send function.
The new UPP.
OSA.hAdds a trailer to the script data in a generic storage descriptor record.
OSErr OSAAddStorageType ( AEDataStorage scriptData, DescType dscType );
A handle to the script data.
The descriptor type to be specified in the trailer added to the script data.
A result code. See “Result Codes.”
The OSAAddStorageType function attaches a trailer to a handle (consequently expanding the data to which the handle refers) or updates an existing trailer.
OSAComp.hObtains a descriptor list containing dialect codes for each of a scripting component’s currently available dialects.
OSAError OSAAvailableDialectCodeList ( ComponentInstance scriptingComponent, AEDesc *resultingDialectCodeList );
A component instance created by a prior call to the Component Manager function OpenDefaultComponent or OpenComponent.
A pointer to the returned descriptor list.
A result code. See “Result Codes.”
Each item in the descriptor list returned by OSAAvailableDialectCodeList is a descriptor record of descriptor type typeInteger containing a dialect code for one of the specified scripting component’s currently available dialects. Dialect codes are defined by individual scripting components.
You can pass any dialect code you obtain using OSAAvailableDialectCodeList to OSAGetDialectInfo to get information about the corresponding dialect.
OSA.hObtains a descriptor list containing information about each of the currently available dialects for a scripting component.
OSAError OSAAvailableDialects ( ComponentInstance scriptingComponent, AEDesc *resultingDialectInfoList );
A component instance created by a prior call to the Component Manager function OpenDefaultComponent or OpenComponent.
A pointer to the returned descriptor list.
A result code. See “Result Codes.”
Each item in the list returned by OSAAvailableDialects is an AE record of descriptor type typeOSADialectInfo. Each descriptor record in the descriptor list contains, at a minimum, four keyword-specified descriptor records with the keywords described in “Dialect Descriptor Constants.”
Rather than calling OSAAvailableDialects to obtain complete dialect information for a scripting component, it is usually more convenient to call OSAAvailableDialectCodeList to get a list of codes for a scripting component’s dialects, then call OSAGetDialectInfo to get information about the specific dialect you’re interested in.
OSA.hObtains the script ID for a script value that corresponds to the data in a descriptor record.
OSAError OSACoerceFromDesc ( ComponentInstance scriptingComponent, const AEDesc *scriptData, SInt32 modeFlags, OSAID *resultingScriptID );
A component instance created by a prior call to the Component Manager function OpenDefaultComponent or OpenComponent.
A pointer to a descriptor record containing the script data to be coerced.
Information used by individual scripting components. To avoid setting mode flag values, specify kOSAModeNull. If the scriptData parameter contains an Apple event, you can use any of the mode flags listed in “Mode Flags.”
A pointer to the resulting script ID for a script value. See the OSAID data type.
A result code. See “Result Codes.”
The OSACoerceFromDesc function coerces the descriptor record in the scriptData parameter to the equivalent script value and returns a script ID for that value.
If you pass OSACoerceFromDesc an Apple event in the scriptData parameter, it returns a script ID for the equivalent compiled script in the resultingScriptValueID parameter. In this case you can specify any of the modeFlags values used by OSACompile to control the way the compiled script is executed.
If you call OSACoerceFromDesc using an instance of the generic scripting component, the generic scripting component uses the default scripting component to perform the coercion.
OSA.hCoerces a script value to a descriptor record of a desired descriptor type.
OSAError OSACoerceToDesc ( ComponentInstance scriptingComponent, OSAID scriptID, DescType desiredType, SInt32 modeFlags, AEDesc *result );
A component instance created by a prior call to the Component Manager function OpenDefaultComponent or OpenComponent.
The script ID for the script value to coerce. See the OSAID data type.
The desired descriptor type of the resulting descriptor record.
Information used by individual scripting components. To avoid setting mode flag values, specify kOSAModeNull.
A pointer to the resulting descriptor record.
A result code. See “Result Codes.”
The OSACoerceToDesc function coerces the script value identified by scriptValueID to a descriptor record of the type specified by the desiredType parameter, if possible. Valid types include all the standard descriptor types, plus any special types supported by the scripting component.
If you want the descriptor type of the descriptor record returned in the result parameter to be the same as the descriptor type returned by a scripting component, use OSACoerceToDesc and specify typeWildCard as the desired type. If you want to get a script value in a form that you can display for humans to read, use OSADisplay.
OSA.h
Compiles the source data for a script and obtain a script ID for a compiled script or a script context.
OSAError OSACompile ( ComponentInstance scriptingComponent, const AEDesc *sourceData, SInt32 modeFlags, OSAID *previousAndResultingScriptID );
A component instance created by a prior call to the Component Manager function OpenDefaultComponent or OpenComponent.
A pointer to a descriptor record containing suitable source data for the specified scripting component.
Information used by individual scripting components. To avoid setting mode flag values, specify kOSAModeNull. Other possible mode flags are listed in “Mode Flags.”
A pointer to 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. See the OSAID data type.
A result code. See “Result Codes.”
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 kOSAModeCompileIntoContext 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.
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.
OSA.hCompiles and executes a script in a single step rather than calling OSACompile and OSAExecute.
OSAError OSACompileExecute ( ComponentInstance scriptingComponent, const AEDesc *sourceData, OSAID contextID, SInt32 modeFlags, OSAID *resultingScriptValueID );
A component instance created by a prior call to the Component Manager function OpenDefaultComponent or OpenComponent.
A pointer to a descriptor record identifying suitable source data for the specified scripting component.
The script ID for the context to be used during script execution. The constant kOSANullScript in this parameter indicates that the scripting component should use its default context. See the OSAID data type.
Information used by individual scripting components. To avoid setting mode flag values, specify kOSAModeNull. Other possible mode flags are listed in “Mode Flags.”
A pointer to the script ID for the script value returned.
A result code. See “Result Codes.”
The OSACompileExecute function compiles source data and executes the resulting compiled script, using the script context identified by the contextID parameter to maintain state information such as the binding of variables. After successfully executing the script, OSACompileExecute disposes of the compiled script and returns either the script ID for the resulting script value or, if execution does not result in a value, the constant kOSANullScript.
If the result c ode returned by OSACompileExecute is a general result code, there was some problem in arranging for the script to be run. If the result code is errOSAScriptError, an error occurred during script execution. In this case, you can obtain more detailed error information by calling OSAScriptError.
OSA.hConverts a script value to an attributed Unicode text string, which your application can display to the user.
OSAError OSACopyDisplayString ( ComponentInstance scriptingComponent, OSAID scriptID, SInt32 modeFlags, CFAttributedStringRef *result );
A component instance created by a prior call to the Component Manager function OpenDefaultComponent or OpenComponent.
The script ID for the script value to display. See the OSAID data type.
Information used by individual scripting components. To avoid setting any mode flags, specify kOSAModeNull. To make the resulting text readable by humans only, so that it can’t be recompiled, specify kOSAModeDisplayForHumans.
If successful, a reference to the script data as an attributed Unicode text string; otherwise not defined.
Because the result parameter returns a copy, the caller is responsible for releasing this string object, according to the rules described in Ownership Policy in Memory Management Programming Guide for Core Foundation.
A result code. See “Result Codes.”
The OSACopyDisplayString function is analogous to OSADisplay, except that it returns the script text as an attributed Unicode text string. An instance of CFAttributedString manages a character string and an associated set of attributes that apply to characters or ranges of characters in the string. You can call ASCopySourceAttributes to get the current AppleScript source style attributes.
OSA.h
Updates script data after editing or recording and to perform undo or revert operations on script data.
OSAError OSACopyID ( ComponentInstance scriptingComponent, OSAID fromID, OSAID *toID );
A component instance created by a prior call to the Component Manager function OpenDefaultComponent or OpenComponent.
The script ID for script data that you want to be associated with the script ID in the toID parameter. See the OSAID data type.
A pointer to the script ID for the script data to be replaced. If the value of this parameter is kOSANullScript, the OSACopyID function returns a new script ID. See the OSAID data type.
A result code. See “Result Codes.”
The OSACopyID function replaces the script data identified by the script ID in the toID parameter with the script data identified by the script ID in the fromID parameter.
OSA.h
Creates a copy of a scripting definition (sdef) from the specified file or bundle.
OSAError OSACopyScriptingDefinition ( const FSRef *ref, SInt32 modeFlags, CFDataRef *sdef );
A file reference to the application file or bundle