If I understand your question correctly, you can grant access to a directory as well.
What @DTS Engineer said, plus…
The way I do this is in 2 steps:
A first NSPanel asks for Directory to select
Then, in the openPanel.begin() closure I ask for saving the file
Now, you will be able to save in this Directory
let openPanel = NSOpenPanel() // to authorize access to directory
openPanel.message = NSLocalizedString("Select Directory)", comment: "")
openPanel.prompt = NSLocalizedString("Select", comment: "")
openPanel.canChooseFiles = false
openPanel.canChooseDirectories = true // To select directrory
openPanel.canCreateDirectories = true
openPanel.begin() { (result2) -> Void in
if result2 == NSApplication.ModalResponse.OK {
// When obtaining access through NSOpenPanel, you don't need to call startAccessingSecurityScopedResource() and stopAccessingSecurityScopedResource(), because the user explicitly granted you access for this session.
let folderUrl = openPanel.url!
// Create file
let savePanel = NSSavePanel()
savePanel.title = NSLocalizedString("File", comment: "")
savePanel.nameFieldStringValue = "" // nothing here, will be entered by user
savePanel.prompt = NSLocalizedString("Create", comment: "")
savePanel.allowedFileTypes = ["XXXX"] // your type
let fileManager = FileManager.default
// Define new file name
savePanel.begin() { (result) -> Void in
if result == NSApplication.ModalResponse.OK {
// write the file
// save bookmarks
}
}
Hope that helps.