is there any way that I can pass a URL to a folder on my system which should be the default window which an NSOpenPanel opens? Thanks!
Update:
NSOpenPanel *ads_open = [[NSOpenPanel openPanel] retain];
[ads_open setDirectoryURL:"file://localhost/System/Library/CoreServices/prndrv"];
I am using the above code which is the directory which I would like to be opened by default. However, the default window that I am getting is still the last one that I have accessed and not the one that I have specified. How can I access the URL directory?
NSOpenPanel *ads_open = [NSOpenPanel openPanel];
[ads_open setDirectoryURL:[NSURL URLWithString:@"file://localhost/System/Library/CoreServices/prndrv"]];
beware to use [NSURL fileURLWithPath:someStringPath]
else its not a valid file url:
NSOpenPanel *panel = [NSOpenPanel openPanel];
// changes promt to Select
[panel setPrompt:@"Select"];
// Enable the selection of files in the dialog.
[panel setCanChooseFiles:NO];
// Enable the selection of directories in the dialog.
[panel setCanChooseDirectories:YES];
//allows multi select
[panel setAllowsMultipleSelection:NO];
if(exists){
[panel setDirectoryURL:[NSURL fileURLWithPath:lastPath]];
}
[panel beginSheetModalForWindow:self.window
completionHandler:^(NSInteger returnCode) {
if (returnCode == NSOKButton)
{
.....
}}];
For Swift 3:
let panel = NSOpenPanel()
panel.directoryURL = URL(fileURLWithPath: "smb://servername/path", isDirectory: true)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With