0

The following code does nothing. No error messages, no save dialog. Why?

let FS = NSSavePanel()
FS.canCreateDirectories = true
FS.allowedFileTypes = ["text", "txt"]
FS.begin { (result: Int) -> Void in
    if result == NSFileHandlingPanelOKButton {
        let exportedFileURL = FS.url
}
}
benwiggy
  • 1,440
  • 17
  • 35
  • In which environment / context ? – vadian Mar 26 '17 at 20:45
  • 1
    Try using the runModal method – Leo Dabus Mar 26 '17 at 20:52
  • https://developer.apple.com/reference/appkit/nssavepanel/1525357-runmodal – Leo Dabus Mar 26 '17 at 20:52
  • runModal does produce a dialog, though I can't see from the docs how to get the results out of it; nor why begin doesn't work in the first place. – benwiggy Mar 27 '17 at 06:59
  • What do you do right after this? Closing any windows? – Willeke Mar 27 '17 at 09:14
  • 1
    "how to get results out of it" See http://stackoverflow.com/a/41198269/2227743 – Eric Aya Mar 27 '17 at 10:32
  • Thanks. Yes, that provides the final piece of the puzzle. So far, I'm just testing these lines in a script: not doing anything else. Would be nice to know why the original code doesn't work, though. – benwiggy Mar 27 '17 at 11:14
  • 3
    `I'm just testing these lines in a script` This might be the cause of your issue. Because `runModal` is synchronous, but `begin` is asynchronous. If your script does not maintain the run loop, it will exit before `begin` has been executed. – Eric Aya Mar 27 '17 at 12:02

0 Answers0