views:

22

answers:

1

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!

A: 
- (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;
        }
    }
}
beeci
This code gets `thisAppName` but doesn't do anything with it.
JWWalker
Thanks, removed.
beeci