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

# NSScriptObjectSpecifier

An abstract class used to represent natural language expressions.

```
class NSScriptObjectSpecifier
```

## Overview

`NSScriptObjectSpecifier` is the abstract superclass for classes that instantiate objects called “object specifiers.” An object specifier represents an AppleScript reference form, which is a natural-language expression such as `words 10 through 20` or `front document` or `words whose color is red`.

The scripting system maps these words or phrases to attributes and relationships of scriptable objects. A reference form rarely occurs in isolation; usually a script statement consists of a series of reference forms preceded by a command and typically connected to each other by `of`, such as:

```objc
get words whose color is blue of paragraph 10 of front document
```

The expression `words whose color is blue of paragraph 10 of front document` specifies a location in the application’s AppleScript object model—the objects the application makes available to scripters. The classes of objects in the object model often closely match the classes of actual objects in the application, but they are not required to. An object specifier locates objects in the running application that correspond to the specified object model objects.

Your application typically creates object specifiers when it implements the `objectSpecifier` method for its scriptable classes. That method is defined by the NSScriptObjectSpecifiers protocol.

It is unlikely that you would ever need to create your own subclass of `NSScriptObjectSpecifier`; the set of valid AppleScript reference forms is determined by Apple Computer and object specifier classes are already implemented for this set. If for some reason you do need to create a subclass, you must override the primitive method [`indicesOfObjectsByEvaluating(withContainer:count:)`](/documentation/Foundation/NSScriptObjectSpecifier/indicesOfObjectsByEvaluating(withContainer:count:)) to return indices to the elements within the container whose values are matched with the child specifier’s key. In addition, you probably need to declare any special instance variables and implement an initializer that invokes super’s designated initializer, [`init(containerClassDescription:containerSpecifier:key:)`](/documentation/Foundation/NSScriptObjectSpecifier/init(containerClassDescription:containerSpecifier:key:)), and initializes these variables.

For a comprehensive treatment of object specifiers, including sample code, see [Object Specifiers](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ScriptableCocoaApplications/SApps_object_specifiers/SAppsObjectSpecifiers.html#//apple_ref/doc/uid/TP40002164-CH3) in [Cocoa Scripting Guide](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ScriptableCocoaApplications/SApps_intro/SAppsIntro.html#//apple_ref/doc/uid/TP40002164).

## Topics

### Obtaining an object specifier for a descriptor

[`+  objectSpecifierWithDescriptor:`](/documentation/Foundation/NSScriptObjectSpecifier/init(descriptor:))

Returns a new object specifier for an Apple event descriptor.

### Initializing an object specifier

[`-  initWithContainerClassDescription:containerSpecifier:key:`](/documentation/Foundation/NSScriptObjectSpecifier/init(containerClassDescription:containerSpecifier:key:))

Returns an `NSScriptObjectSpecifier` object initialized with the given attributes.

[`-  initWithContainerSpecifier:key:`](/documentation/Foundation/NSScriptObjectSpecifier/init(containerSpecifier:key:))

Returns an `NSScriptObjectSpecifier` object initialized with a given container specifier  and key.

### Evaluating an object specifier

[`-  indicesOfObjectsByEvaluatingWithContainer:count:`](/documentation/Foundation/NSScriptObjectSpecifier/indicesOfObjectsByEvaluating(withContainer:count:))

This primitive method must be overridden by subclasses to return a pointer to an array of indices identifying objects in the key of a given container that are identified by the receiver of the message.

[`objectsByEvaluatingSpecifier`](/documentation/Foundation/NSScriptObjectSpecifier/objectsByEvaluatingSpecifier)

Returns the actual object represented by the nested series of object specifiers.

[`-  objectsByEvaluatingWithContainers:`](/documentation/Foundation/NSScriptObjectSpecifier/objectsByEvaluating(withContainers:))

Returns the actual object or objects specified by the receiver as evaluated in the context of given container object.

### Getting, testing, and setting containers

[`containerClassDescription`](/documentation/Foundation/NSScriptObjectSpecifier/containerClassDescription)

Sets the class description of the receiver’s container specifier to a given specifier.

[`containerIsObjectBeingTested`](/documentation/Foundation/NSScriptObjectSpecifier/containerIsObjectBeingTested)

Sets whether the receiver’s container should be an object involved in a filter reference or the top-level object.

[`containerIsRangeContainerObject`](/documentation/Foundation/NSScriptObjectSpecifier/containerIsRangeContainerObject)

Sets whether the receiver’s container is to be the container for a range specifier or a top-level object.

[`containerSpecifier`](/documentation/Foundation/NSScriptObjectSpecifier/container)

Sets the container specifier of the receiver.

### Getting and setting child references

[`childSpecifier`](/documentation/Foundation/NSScriptObjectSpecifier/child)

Sets the receiver’s child reference.

### Getting and setting object keys

[`key`](/documentation/Foundation/NSScriptObjectSpecifier/key)

Sets the key of the receiver.

[`keyClassDescription`](/documentation/Foundation/NSScriptObjectSpecifier/keyClassDescription)

Returns the class description of the objects specified by the receiver.

### Getting evaluation errors

[`evaluationErrorSpecifier`](/documentation/Foundation/NSScriptObjectSpecifier/evaluationError)

Returns the object specifier in which an evaluation error occurred.

[`evaluationErrorNumber`](/documentation/Foundation/NSScriptObjectSpecifier/evaluationErrorNumber)

Sets the value of the evaluation error.

### Getting a descriptor for the object specifier

[`descriptor`](/documentation/Foundation/NSScriptObjectSpecifier/descriptor)

Returns an Apple event descriptor that represents the receiver.

### Constants

[NSScriptObjectSpecifier—Specifier Evaluation Errors](/documentation/Foundation/Specifier-Evaluation-Errors)

`NSScriptObjectSpecifier` provides the following constants for error codes for specific problems evaluating specifiers:

## Relationships

### Inherited By

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

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

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

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

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

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

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

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

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

### Conforms To

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

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

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

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

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

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

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

### 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)