I create files with proprietary extension (just a ".string") and want to hide it to the user.
I am trying the following :
let savePanel = NSSavePanel()
savePanel.title = "My file"
savePanel.prompt = "Create"
savePanel.beginWithCompletionHandler() { (result) -> Void in
if (result == NSFileHandlingPanelOKButton) {
let fileWithExtensionURL = savePanel.URL!.URLByAppendingPathExtension("myExt")
saveFile() // Create the file
// try to hide extension in Finder
do { try NSFileManager.defaultManager().setAttributes([NSFileExtensionHidden: NSNumber(bool: true)], ofItemAtPath: fileWithExtensionURL.path!) } /
catch { Swift.print("Unable to hide extension", error) }
}
}
The try is successful (no error message), but extension still shows in Finder.
Writing is done with key archiving :
let data = NSMutableData()
let archiver = NSKeyedArchiver(forWritingWithMutableData: data)
// encode objects
archiver.finishEncoding()
data.writeToURL(fileWithExtensionURL, atomically: true)
1. Is it a question of access rights to the file ? How to set it ?
Note : When I look at file information in Finder , the check box "hide extension" is set ON but disabled
2. I would also need this file to launch automatically the application if double clicked. How can I set it ?
3. I understand this should be done with UTI instead of mere file extension ; but my app is not document based, and I've found nowhere how to create UTI for the files in this case.
Thanks for any help on this.