I want to display a dialog which allows the user to browse through their current applications (/Applications) and I need to get the full path of that application (selected). How would I go about this? Code samples are appreciated.
Thanks.
Something like this would be a good start:
NSArray *appsDirs = NSSearchPathForDirectoriesInDomains(NSApplicationDirectory,
NSLocalDomainMask, YES);
NSString *appsDir = nil;
if ([appsDirs count]) appsDir = [appsDirs objectAtIndex:0];
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
[openPanel setTitle:NSLocalizedString(@"Add Application", @"")];
[openPanel setMessage:NSLocalizedString(@"Choose the application to add.", @"")];
[openPanel setPrompt:NSLocalizedString(@"Add Application", @"")];
[openPanel setAllowsMultipleSelection:YES]; // ?
[openPanel setCanChooseDirectories:NO];
[openPanel setDelegate:self];
NSInteger result = [openPanel runModalForDirectory:appsDir
file:nil
types:
[NSArray arrayWithObject:NSFileTypeForHFSTypeCode('APPL')]];
if (result == NSOKButton) {
NSArray *fileURLs = [openPanel URLs];
for (NSURL *URL in fileURLs) {
NSString *path = [URL path];
// add path, etc.
}
}
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