---
title: "execute(withInput:completionHandler:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsuserautomatortask/execute(withinput:completionhandler:)"
---

# execute(withInput:completionHandler:)

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

## Declaration

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

```swift
func execute(withInput input: (any NSSecureCoding)?) async throws -> Any
```

## Parameters

- `input`: The automator task.
- `handler`: The completion handler Block that returns the result or an error. See doc://com.apple.foundation/documentation/Foundation/NSUserAutomatorTask/CompletionHandler.

## Discussion

Discussion The Automator workflow will execute using the 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

### Related Documentation

- [init(url:)](foundation/nsuserscripttask/init(url:)-2qgls.md)

### Executing Automator Tasks

- [variables](foundation/nsuserautomatortask/variables.md)
