NSOpenPanel should have a setting to only allow the user to select writable paths
Originator: | sindresorhus | ||
Number: | rdar://46998745 | Date Originated: | 02-Jan-2019 12:22 PM |
Status: | Open (Duplicate of 3300000) | Resolved: | |
Product: | macOS + SDK | Product Version: | macOS 10.14.2 |
Classification: | Feature (New) | Reproducible: | Always |
Summary: I already opened rdar://46998451, but I think the use-case of "only wanting a path you can write to" such a common use-case that it should be handled by `NSOpenPanel`. My use-case: I use `NSOpenPanel` to let the user select a directory where my app can output some files. I want to inform the user early, while the open panel is still shown, if the user tries to select a read-only directory, as I wouldn't be able to write to that. Even if rdar://46998451 is fixed, I still think this feature has merits on its own. Steps to Reproduce: I have this code to open the panel: ```swift @NSApplicationMain final class AppDelegate: NSObject, NSApplicationDelegate { func convert() { let panel = NSOpenPanel() panel.delegate = self panel.canChooseFiles = false panel.canChooseDirectories = true panel.canCreateDirectories = true panel.allowsMultipleSelection = false panel.prompt = "Convert" panel.message = "Choose where to save the converted images" panel.beginSheetModal(for: window) { if $0 == .OK { self.startConversion(urls, outputDirectory: panel.urls.first!) } } } } ``` Expected Results: I expected to be able to set a property, let's call it `panel.allowReadOnlyPaths = false`, to make NSOpenPanel show an error if the user tries to select a read-only file or directory. Actual Results: Because of rdar://46998451, I can't even implement this manually, so I have to end up with a user unfriendly workaround that only shows an error after the open panel is dismissed, and then I have to show the open panel again. Version: macOS 10.14.2 Notes:
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
Apple Developer Relations
Engineering has determined that your bug report is a duplicate of another issue (3300000) and will be closed.
Stack Overflow question
https://stackoverflow.com/questions/6844383/nssavepanel-and-the-sandbox
Related Radar
https://openradar.appspot.com/radar?id=5004220688236544
Twitter thread
https://twitter.com/sindresorhus/status/1080417460359176192