<!--
{
  "availability" : [
    "macOS: 10.8.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSUserAutomatorTask/execute(withInput:completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSUserAutomatorTask(im)executeWithInput:completionHandler:"
  },
  "title" : "execute(withInput:completionHandler:)"
}
-->

# execute(withInput:completionHandler:)

Execute the Automator workflow by providing it as securely coded input.

```
func execute(withInput input: (any NSSecureCoding)?, completionHandler handler: NSUserAutomatorTask.CompletionHandler? = nil)
```

## Parameters

`input`

The automator task.

`handler`

The completion handler Block that returns the result or an error. See [`NSUserAutomatorTask.CompletionHandler`](/documentation/Foundation/NSUserAutomatorTask/CompletionHandler).

## Discussion

The Automator workflow will execute using the [`variables`](/documentation/Foundation/NSUserAutomatorTask/variables) property values.

This method should be invoked no more than once for a given instance of the class.

If the script completed normally, the completion handler’s `error` parameter will be `nil`.

## See Also

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

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



---

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)