Reputation: 13771
I'm trying to get a list of applications that are capable of opening a type of file. So far I've been able to get the name of a single application using NSWorkspace
's getInfoForFile:application:type:
method.
Is there any API that I can call to get a list of applications capable of opening a file?
Upvotes: 8
Views: 1411
Reputation: 61228
I believe you'll need to use Launch Services to get a list. LSCopyApplicationURLsForURL "Locates all known applications suitable for opening an item designated by URL."
Seems if you pass in a file URL, you should get your (CFArrayRef) list of applications.
Upvotes: 11
Reputation: 13771
For future reference, I was interested specifically in getting a list of applications that are capable of opening a particular document type. The accepted answer pointed in the right direction but was not a complete solution as LSCopyApplicaionURLsForURL
and its sibling LSCopyAllRoleHandlersForContentType
return a bundle identifier, not the application itself. Therefore I still needed the application's:
Below is the code I've used to retrieve all of that information:
NSArray* handlers = LSCopyAllRoleHandlersForContentType(@"com.adobe.pdf", kLSRolesAll);
for (NSString* bundleIdentifier in handlers) {
NSString* path = [[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier: bundleIdentifier];
NSString* name = [[NSFileManager defaultManager] displayNameAtPath: path];
NSImage* icon = [[NSWorkspace sharedWorkspace] iconForFile: path];
}
Upvotes: 8