Mac Developer Library

Developer

Foundation Framework Reference NSAppleScript Class Reference

Options
Deployment Target:

On This Page
Language:

NSAppleScript

The NSAppleScript class provides the ability to load, compile, and execute scripts. More...

Inheritance


Conforms To


Import Statement


import Foundation @import Foundation;

Availability


Available in OS X v10.2 and later.
  • Initializes a newly allocated script instance from the source identified by the passed URL.

    Declaration

    Swift

    init?(contentsOfURL url: NSURL, error errorInfo: AutoreleasingUnsafeMutablePointer<NSDictionary?>)

    Objective-C

    - (instancetype)initWithContentsOfURL:(NSURL *)url error:(NSDictionary **)errorInfo

    Parameters

    url

    A URL that locates a script, in either text or compiled form.

    errorInfo

    On return, if an error occurs, a pointer to an error information dictionary.

    Return Value

    The initialized script object, nil if an error occurs.

    Discussion

    This method is a designated initializer for NSAppleScript.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.2 and later.

  • init(source:) initWithSource: Designated Initializer

    Initializes a newly allocated script instance from the passed source.

    Declaration

    Swift

    init?(source source: String)

    Objective-C

    - (instancetype)initWithSource:(NSString *)source

    Parameters

    source

    A string containing the source code of a script.

    Return Value

    The initialized script object, nil if an error occurs.

    Discussion

    This method is a designated initializer for NSAppleScript.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.2 and later.

  • Returns a Boolean value that indicates whether the receiver's script has been compiled.

    Declaration

    Objective-C

    - (BOOL)isCompiled

    Return Value

    YEStrue if the receiver is already compiled, NOfalse otherwise.

    Import Statement

    Availability

    Available in OS X v10.2 and later.

  • Returns the script source for the receiver.

    Declaration

    Swift

    var source: String? { get }

    Objective-C

    @property(readonly, copy) NSString *source

    Return Value

    The script source code of the receiver if it is available, nil otherwise.

    Discussion

    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.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.2 and later.

  • Compiles the receiver, if it is not already compiled.

    Declaration

    Swift

    func compileAndReturnError(_ errorInfo: AutoreleasingUnsafeMutablePointer<NSDictionary?>) -> Bool

    Objective-C

    - (BOOL)compileAndReturnError:(NSDictionary **)errorInfo

    Parameters

    errorInfo

    On return, if an error occurs, a pointer to an error information dictionary.

    Return Value

    YEStrue for success or if the script was already compiled, NOfalse otherwise.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.2 and later.

  • Executes the receiver, compiling it first if it is not already compiled.

    Declaration

    Swift

    func executeAndReturnError(_ errorInfo: AutoreleasingUnsafeMutablePointer<NSDictionary?>) -> NSAppleEventDescriptor?

    Objective-C

    - (NSAppleEventDescriptor *)executeAndReturnError:(NSDictionary **)errorInfo

    Parameters

    errorInfo

    On return, if an error occurs, a pointer to an error information dictionary.

    Return Value

    The result of executing the event, or nil if an error occurs.

    Discussion

    Any changes to property values caused by executing the script do not persist.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.2 and later.

  • Executes an Apple event in the context of the receiver, as a means of allowing the application to invoke a handler in the script.

    Declaration

    Swift

    func executeAppleEvent(_ event: NSAppleEventDescriptor, error errorInfo: AutoreleasingUnsafeMutablePointer<NSDictionary?>) -> NSAppleEventDescriptor?

    Objective-C

    - (NSAppleEventDescriptor *)executeAppleEvent:(NSAppleEventDescriptor *)event error:(NSDictionary **)errorInfo

    Parameters

    event

    The Apple event to execute.

    errorInfo

    On return, if an error occurs, a pointer to an error information dictionary.

    Return Value

    The result of executing the event, or nil if an error occurs.

    Discussion

    Compiles the receiver before executing it if it is not already compiled.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.2 and later.

  • If the result of initWithContentsOfURL:error:, compileAndReturnError:, executeAndReturnError:, or executeAppleEvent:error:, signals failure (nil, NOfalse, 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.

    Declaration

    Swift

    let NSAppleScriptErrorMessage: NSString! let NSAppleScriptErrorNumber: NSString! let NSAppleScriptErrorAppName: NSString! let NSAppleScriptErrorBriefMessage: NSString! let NSAppleScriptErrorRange: NSString!

    Objective-C

    extern NSString *NSAppleScriptErrorMessage; extern NSString *NSAppleScriptErrorNumber; extern NSString *NSAppleScriptErrorAppName; extern NSString *NSAppleScriptErrorBriefMessage; extern NSString *NSAppleScriptErrorRange;

    Constants

    • NSAppleScriptErrorMessage

      NSAppleScriptErrorMessage

      An NSString that supplies a detailed description of the error condition.

      Available in OS X v10.2 and later.

    • NSAppleScriptErrorNumber

      NSAppleScriptErrorNumber

      An NSNumber that specifies the error number.

      Available in OS X v10.2 and later.

    • NSAppleScriptErrorAppName

      NSAppleScriptErrorAppName

      An NSString that specifies the name of the application that generated the error.

      Available in OS X v10.2 and later.

    • NSAppleScriptErrorBriefMessage

      NSAppleScriptErrorBriefMessage

      An NSString that provides a brief description of the error.

      Available in OS X v10.2 and later.

    • NSAppleScriptErrorRange

      NSAppleScriptErrorRange

      An NSValue that specifies a range.

      Available in OS X v10.2 and later.

    Import Statement