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

# NSUserScriptTask

An object that executes scripts.

```
class NSUserScriptTask
```

## Overview

The [`NSUserScriptTask`](/documentation/Foundation/NSUserScriptTask) class is able to run all the scripts normally run by the one of its subclasses, however it ignores the results. It is intended to execute user-supplied scripts and will execute them outside of the application’s sandbox, if any.

If you need to execute scripts and get the input and output information use the [`NSUserUnixTask`](/documentation/Foundation/NSUserUnixTask), [`NSUserAppleScriptTask`](/documentation/Foundation/NSUserAppleScriptTask), and [`NSUserAutomatorTask`](/documentation/Foundation/NSUserAutomatorTask) sub classes.

## Topics

### Specifying the Script

[`-  initWithURL:error:`](/documentation/Foundation/NSUserScriptTask/init(url:)-2qgls)

Return a user script task instance given a URL for a script file.

[`scriptURL`](/documentation/Foundation/NSUserScriptTask/scriptURL)

The URL of the script file.

### Executing the User Script

[`-  executeWithCompletionHandler:`](/documentation/Foundation/NSUserScriptTask/execute(completionHandler:))

Executes the script with no input and ignoring any result.

### Constants

[`CompletionHandler`](/documentation/Foundation/NSUserScriptTask/CompletionHandler)

Implement this block to retrieve the error of the script executed by [`execute(completionHandler:)`](/documentation/Foundation/NSUserScriptTask/execute(completionHandler:)).

## Relationships

### Conforms To

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

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

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

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

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

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

### Inherited By

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

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

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

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