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

# NSScriptExecutionContext

The context in which the current script command is executed.

```
class NSScriptExecutionContext
```

## Overview

An `NSScriptExecutionContext` object is a shared instance (there is only one instance of the class) that represents the context in which the current script command is executed. `NSScriptExecutionContext` tracks global state relating to the command being executed, especially the top-level container object (that is, the container implied by a specifier object that specifies no container) used in an evaluation of an [`NSScriptObjectSpecifier`](/documentation/Foundation/NSScriptObjectSpecifier) object.

In most cases, the top-level container for a complete series of nested object specifiers is automatically set to the application object (`NSApp`), and you can get this object with the [`topLevelObject`](/documentation/Foundation/NSScriptExecutionContext/topLevelObject) method. But you can also set this top-level container to something else (using [`topLevelObject`](/documentation/Foundation/NSScriptExecutionContext/topLevelObject)) if the situation warrants it.

It is unlikely that you will need to subclass `NSScriptExecutionContext`.

## Topics

### Getting the current context

[`+  sharedScriptExecutionContext`](/documentation/Foundation/NSScriptExecutionContext/shared())

Returns the shared `NSScriptExecutionContext` instance.

### Getting and setting the container object

[`topLevelObject`](/documentation/Foundation/NSScriptExecutionContext/topLevelObject)

Sets the top-level object for an object-specifier evaluation.

[`objectBeingTested`](/documentation/Foundation/NSScriptExecutionContext/objectBeingTested)

Sets the top-level container object currently being tested in a “whose” qualifier to a given object.

[`rangeContainerObject`](/documentation/Foundation/NSScriptExecutionContext/rangeContainerObject)

Sets the top-level container object for a range-specifier evaluation to a give object.

## Relationships

### Conforms To

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

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

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

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

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

[`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)