tags:

views:

78

answers:

2

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?

+2  A: 

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.

Joshua Nozzi
A: 

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:

  • Path
  • Display Name; and
  • Icon

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];
}
Bryan Kyle