<!--
{
  "availability" : [
    "macCatalyst: -",
    "macOS: 10.0.0 - 10.6.0"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSSavePanel/runModalForDirectory:file:",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSSavePanel(im)runModalForDirectory:file:"
  },
  "title" : "runModalForDirectory:file:"
}
-->

# runModalForDirectory:file:

Initializes the panel to the directory and file specified, if any, then displays it and begins its modal event loop.

```
- (NSInteger) runModalForDirectory:(NSString *) path file:(NSString *) name;
```

## Parameters

`path`

Directory whose files the panel displays. When `nil`, the directory is the same directory used in the previous invocation of the panel; this is probably the best choice for most situations.

`name`

Specifies a particular file in `path` that is selected when the Save panel is presented to a user. When `nil`, no file is initially selected.

## Return Value

`NSFileHandlingPanelOKButton` (if the user clicks the OK button) or `NSFileHandlingPanelCancelButton` (if the user clicks the Cancel button).

## Discussion

This method invokes `NSApplication`’s [`runModal(for:)`](/documentation/AppKit/NSApplication/runModal(for:)) method with `self` as the argument.

## See Also

[`func runModal(for: NSWindow) -> NSApplication.ModalResponse`](/documentation/AppKit/NSApplication/runModal(for:))

Starts a modal event loop for the specified window.

[`func runModal() -> NSApplication.ModalResponse`](/documentation/AppKit/NSSavePanel/runModal())

Displays the panel and begins its event loop with the current working (or last-selected) directory as the default starting point.



---

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)