<!--
{
  "availability" : [
    "macOS: 12.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSWorkspace/setDefaultApplication(at:toOpenFileAt:completion:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSWorkspace(im)setDefaultApplicationAtURL:toOpenFileAtURL:completionHandler:"
  },
  "title" : "setDefaultApplication(at:toOpenFileAt:completion:)"
}
-->

# setDefaultApplication(at:toOpenFileAt:completion:)

Sets the default app to use when opening a specific file.

```
func setDefaultApplication(at applicationURL: URL, toOpenFileAt url: URL, completion completionHandler: (@Sendable ((any Error)?) -> Void)? = nil)
```

## Parameters

`applicationURL`

The URL of the default app to use when opening the file.

`url`

The URL of the file to open.

`completionHandler`

The completion handler to call after the operation completes.

## Discussion

This method sets the default app to use for a specific file (rather than all files of that content type). The system requires write access to the specified `url` before it can make the change.

If a change requires user consent, the system asks the user for consent asynchronously before invoking the completion handler.

This function doesn’t apply to non-file URLs.

---

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)