---
title: "init(url:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/nsuserscripttask/init(url:)-2qgls"
---

# init(url:)

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

## Declaration

```swift
init(url: URL) throws
```

## Parameters

- `url`: The script URL.

## Return Value

Return Value An instance of an NSUserScriptTask subclass or nil if the file does not appear to match any of the known types.

## Discussion

Discussion The returned object will be of one of the specific sub-classes (NSUserUnixTask, NSUserAppleScriptTask, and NSUserAutomatorTask), or nil if the file does not appear to match any of the known types. If invoked from a subclass, the result will be that class or nil. note: In Swift, this API is imported as an initializer and is marked with the throws keyword to indicate that it throws an error in cases of failure. You call this method in a try expression and handle any errors in the catch clauses of a do statement, as described in Error Handling in The Swift Programming Language and About Imported Cocoa Error Parameters.

## See Also

### Specifying the Script

- [scriptURL](foundation/nsuserscripttask/scripturl.md)
