---
title: NSAppleScript
framework: foundation
role: symbol
role_heading: Class
path: foundation/nsapplescript
---

# NSAppleScript

An object that provides the ability to load, compile, and execute scripts.

## Declaration

```swift
class NSAppleScript
```

## Overview

Overview 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 errorMessage, are described in the Constants section. See also NSAppleScript Additions Reference in the Application Kit framework, which defines a method that returns the syntax-highlighted source code for a script.

## Topics

### Initializing a Script

- [init(contentsOf:error:)](foundation/nsapplescript/init(contentsof:error:).md)
- [init(source:)](foundation/nsapplescript/init(source:).md)

### Getting Information About a Script

- [isCompiled](foundation/nsapplescript/iscompiled.md)
- [source](foundation/nsapplescript/source.md)

### Compiling and Executing a Script

- [compileAndReturnError(_:)](foundation/nsapplescript/compileandreturnerror(_:).md)
- [executeAndReturnError(_:)](foundation/nsapplescript/executeandreturnerror(_:).md)
- [executeAppleEvent(_:error:)](foundation/nsapplescript/executeappleevent(_:error:).md)

### Constants

- [Error Dictionary Keys](foundation/error-dictionary-keys.md)

### Instance Properties

- [richTextSource](foundation/nsapplescript/richtextsource.md)

### Initializers

- [init(contentsOfURL:error:)](foundation/nsapplescript/init(contentsofurl:error:).md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCopying](foundation/nscopying.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
