<!--
{
  "availability" : [
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSScriptCommand",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSScriptCommand"
  },
  "title" : "NSScriptCommand"
}
-->

# NSScriptCommand

A self-contained scripting statement.

```
class NSScriptCommand
```

## Overview

An instance of [`NSScriptCommand`](/documentation/Foundation/NSScriptCommand) represents a scripting statement, such as `set word 5 of the front document to word 1 of the second document`, and contains the information needed to perform the operation specified by the statement.

When an Apple event reaches a Cocoa application, Cocoa’s built-in scripting support transforms it into a script command (that is, an instance of `NSScriptCommand` or one of the subclasses provided by Cocoa scripting or by your application) and executes the command in the context of the application. Executing a command means either invoking the selector associated with the command on the object or objects designated to receive the command, or having the command perform its default implementation method ([`performDefaultImplementation()`](/documentation/Foundation/NSScriptCommand/performDefaultImplementation())).

Your application most likely calls methods of `NSScriptCommand` to extract the command arguments. You do this either in the `performDefaultImplementation` method of a command subclass you have created, or in an object method designated as the selector to handle a particular command.

As part of Cocoa’s standard scripting implementation, `NSScriptCommand` and its subclasses can handle the default command set for AppleScript’s Standard suite for most applications without any subclassing. The Standard suite includes commands such as `copy`, `count`, `create`, `delete`, `exists`, and `move`, as well as common object classes such as `application`, `document`, and `window`.

For more information on working with script commands, see [Script Commands](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ScriptableCocoaApplications/SApps_script_cmds/SAppsScriptCmds.html#//apple_ref/doc/uid/20001242) in [Cocoa Scripting Guide](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ScriptableCocoaApplications/SApps_intro/SAppsIntro.html#//apple_ref/doc/uid/TP40002164).

## Topics

### Initializing a script command

[`-  initWithCommandDescription:`](/documentation/Foundation/NSScriptCommand/init(commandDescription:))

Returns an a script command object initialized from the passed command description.

### Getting the current command

[`+  currentCommand`](/documentation/Foundation/NSScriptCommand/current())

If a command is being executed in the current thread by Cocoa scripting’s built-in Apple event handling, return the command.

### Getting the Apple event

[`appleEvent`](/documentation/Foundation/NSScriptCommand/appleEvent)

If the receiver was constructed by Cocoa scripting’s built-in Apple event handling, returns the Apple event descriptor from which it was constructed.

### Executing the command

[`-  executeCommand`](/documentation/Foundation/NSScriptCommand/execute())

Executes the command if it is valid and returns the result, if any.

[`-  performDefaultImplementation`](/documentation/Foundation/NSScriptCommand/performDefaultImplementation())

Overridden by subclasses to provide a default implementation for the command represented by the receiver.

### Accessing receivers

[`evaluatedReceivers`](/documentation/Foundation/NSScriptCommand/evaluatedReceivers)

Returns the object or objects to which the command is to be sent (called both the “receivers” or “targets” of script commands).

[`receiversSpecifier`](/documentation/Foundation/NSScriptCommand/receiversSpecifier)

Sets the object specifier to `receiversSpec` that, when evaluated, indicates the receiver or receivers of the command.

### Accessing arguments

[`arguments`](/documentation/Foundation/NSScriptCommand/arguments)

Sets the arguments of the command to `args`.

[`evaluatedArguments`](/documentation/Foundation/NSScriptCommand/evaluatedArguments)

Returns a dictionary containing the arguments of the command, evaluated from object specifiers to objects if necessary. The keys in the dictionary are the argument names.

### Accessing the direct parameter

[`directParameter`](/documentation/Foundation/NSScriptCommand/directParameter)

Sets the object that corresponds to the direct parameter of the Apple event from which the receiver derives.

### Getting command information

[`commandDescription`](/documentation/Foundation/NSScriptCommand/commandDescription)

Returns the command description for the command.

[`wellFormed`](/documentation/Foundation/NSScriptCommand/isWellFormed)

Returns a Boolean value indicating whether the receiver is well formed according to its command description.

### Handling script execution errors

[`scriptErrorExpectedTypeDescriptor`](/documentation/Foundation/NSScriptCommand/scriptErrorExpectedTypeDescriptor)

Sets a descriptor for the expected type that will be put in the reply Apple event if the sender requested a reply, execution of the receiver completes, and an error number was set.

[`scriptErrorNumber`](/documentation/Foundation/NSScriptCommand/scriptErrorNumber)

Sets a script error number that is associated with the execution of the command and is returned in the reply Apple event, if a reply was requested by the sender.

[`scriptErrorOffendingObjectDescriptor`](/documentation/Foundation/NSScriptCommand/scriptErrorOffendingObjectDescriptor)

Sets a descriptor for an object that will be put in the reply Apple event if the sender requested a reply, execution of the receiver completes, and an error number was set.

[`scriptErrorString`](/documentation/Foundation/NSScriptCommand/scriptErrorString)

Sets a script error string that is associated with execution of the command.

### Suspending and resuming commands

[`-  suspendExecution`](/documentation/Foundation/NSScriptCommand/suspendExecution())

Suspends the execution of the receiver.

[`-  resumeExecutionWithResult:`](/documentation/Foundation/NSScriptCommand/resumeExecution(withResult:))

If a successful, unmatched, invocation of [`suspendExecution()`](/documentation/Foundation/NSScriptCommand/suspendExecution()) has been made, resume the execution of the command.

### Constants

[NSScriptCommand—General Command Execution Errors](/documentation/Foundation/general-command-execution-errors)

`NSScriptCommand` uses the following error codes for general command execution problems:

## Relationships

### Inherited By

[`NSDeleteCommand`](/documentation/Foundation/NSDeleteCommand)

[`NSCloseCommand`](/documentation/Foundation/NSCloseCommand)

[`NSGetCommand`](/documentation/Foundation/NSGetCommand)

[`NSQuitCommand`](/documentation/Foundation/NSQuitCommand)

[`NSMoveCommand`](/documentation/Foundation/NSMoveCommand)

[`NSSetCommand`](/documentation/Foundation/NSSetCommand)

[`NSCreateCommand`](/documentation/Foundation/NSCreateCommand)

[`NSCountCommand`](/documentation/Foundation/NSCountCommand)

[`NSCloneCommand`](/documentation/Foundation/NSCloneCommand)

[`NSExistsCommand`](/documentation/Foundation/NSExistsCommand)

### Conforms To

[`NSCoding`](/documentation/Foundation/NSCoding)

[`Hashable`](/documentation/Swift/Hashable)

[`CVarArg`](/documentation/Swift/CVarArg)

[`Equatable`](/documentation/Swift/Equatable)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)