I have the list of the applications for given file extension (using LSCopyApplicationURLsForURL). I want to change the default file association from code upon selecting one of the applications from the above call. Is there a way to do this?
Thanks!
I have the list of the applications for given file extension (using LSCopyApplicationURLsForURL). I want to change the default file association from code upon selecting one of the applications from the above call. Is there a way to do this?
Thanks!
- (void) setApplication:(NSString *)applicationName forExtension:(NSString *)extension {
NSArray *appPaths = [self getApplicationListForExtension:extension];
for (NSString *appPath in appPaths) {
if ([appPath rangeOfString:applicationName].location != NSNotFound) {
NSArray *UTIs = (NSArray *)UTTypeCreateAllIdentifiersForTag(kUTTagClassFilenameExtension,
(CFStringRef)extension,
nil);
for (NSString *UTI in UTIs) {
LSSetDefaultRoleHandlerForContentType((CFStringRef)UTI,
kLSRolesEditor,
(CFStringRef)[[NSBundle bundleWithPath:appPath] bundleIdentifier]);
}
[UTIs release];
break;
}
}
}