Inherits from | |
Conforms to | |
Framework | /System/Library/Frameworks/Foundation.framework |
Availability | Available in Mac OS X v10.2 and later. |
Companion guide | |
Declared in | NSAppleScript.h |
Related sample code |
The NSAppleScript
class provides the ability to load, compile, and execute scripts.
This class provides applications with the ability to
load a script from a URL or from a text string
compile or execute a script or an individual Apple event
obtain an NSAppleEventDescriptor
containing the reply from an executed script or event
obtain an attributed string for a compiled script, suitable for display in a script editor
obtain various kinds of information about any errors that may occur
Important:
NSAppleScript
provides the executeAppleEvent:error:
method so that you can send an Apple event to invoke a handler in a script. (In an AppleScript script, a handler is the equivalent of a function.) However, you cannot use this method to send Apple events to other applications.
When you create an instance of NSAppleScript
object, you can use a URL to specify a script that can be in either text or compiled form, or you can supply the script as a string. Should an error occur when compiling or executing the script, several of the methods return a dictionary containing error information. The keys for obtaining error information, such as NSAppleScriptErrorMessage
, are described in the Constants section.
See also NSAppleScript Additions in the Application Kit framework, which defines a method that returns the syntax-highlighted source code for a script.
Compiles the receiver, if it is not already compiled.
- (BOOL)compileAndReturnError:(NSDictionary **)errorInfo
On return, if an error occurs, a pointer to an error information dictionary.
YES
for success or if the script was already compiled, NO
otherwise.
NSAppleScript.h
Executes the receiver, compiling it first if it is not already compiled.
- (NSAppleEventDescriptor *)executeAndReturnError:(NSDictionary **)errorInfo
On return, if an error occurs, a pointer to an error information dictionary.
The result of executing the event, or nil
if an error occurs.
Any changes to property values caused by executing the script do not persist.
NSAppleScript.h
Executes an Apple event in the context of the receiver, as a means of allowing the application to invoke a handler in the script.
- (NSAppleEventDescriptor *)executeAppleEvent:(NSAppleEventDescriptor *)event error:(NSDictionary **)errorInfo
The Apple event to execute.
On return, if an error occurs, a pointer to an error information dictionary.
The result of executing the event, or nil
if an error occurs.
Compiles the receiver before executing it if it is not already compiled.
NSAppleScript.h
Initializes a newly allocated script instance from the source identified by the passed URL.
- (id)initWithContentsOfURL:(NSURL *)url error:(NSDictionary **)errorInfo
A URL that locates a script, in either text or compiled form.
On return, if an error occurs, a pointer to an error information dictionary.
The initialized script object, nil
if an error occurs.
This method is a designated initializer for NSAppleScript
.
NSAppleScript.h
Initializes a newly allocated script instance from the passed source.
- (id)initWithSource:(NSString *)source
A string containing the source code of a script.
The initialized script object, nil
if an error occurs.
This method is a designated initializer for NSAppleScript
.
NSAppleScript.h
Returns a Boolean value that indicates whether the receiver's script has been compiled.
- (BOOL)isCompiled
YES
if the receiver is already compiled, NO
otherwise.
NSAppleScript.h
Returns the script source for the receiver.
- (NSString *)source
The script source code of the receiver if it is available, nil
otherwise.
It is possible for an NSAppleScript
that has been instantiated with initWithContentsOfURL:error:
to be a script for which the source code is not available but is nonetheless executable.
NSAppleScript.h
If the result of initWithContentsOfURL:error:
, compileAndReturnError:
, executeAndReturnError:
, or executeAppleEvent:error:
, signals failure (nil
, NO
, nil
, or nil
, respectively), a pointer to an autoreleased dictionary is put at the location pointed to by the error parameter. The error info dictionary may contain entries that use any combination of the following keys, including no entries at all.
extern NSString *NSAppleScriptErrorMessage; extern NSString *NSAppleScriptErrorNumber; extern NSString *NSAppleScriptErrorAppName; extern NSString *NSAppleScriptErrorBriefMessage; extern NSString *NSAppleScriptErrorRange;
NSAppleScriptErrorMessage
An NSString
that supplies a detailed description of the error condition.
Available in Mac OS X v10.2 and later.
Declared in NSAppleScript.h
.
NSAppleScriptErrorNumber
An NSNumber
that specifies the error number.
Available in Mac OS X v10.2 and later.
Declared in NSAppleScript.h
.
NSAppleScriptErrorAppName
An NSString
that specifies the name of the application that generated the error.
Available in Mac OS X v10.2 and later.
Declared in NSAppleScript.h
.
NSAppleScriptErrorBriefMessage
An NSString
that provides a brief description of the error.
Available in Mac OS X v10.2 and later.
Declared in NSAppleScript.h
.
NSAppleScriptErrorRange
An NSValue
that specifies a range.
Available in Mac OS X v10.2 and later.
Declared in NSAppleScript.h
.
NSAppleScript.h
© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-07-10)