Get a list of applications that can open a file type

I am trying to get a list of applications that can open a file type. So far, I have managed to get the name of a single application using the NSWorkspace method getInfoForFile:application:type:

Is there any API I can call to get a list of applications that can open a file?

+7
cocoa macos
source share
2 answers

I believe that you will need to use Launch Services to get the list. LSCopyApplicationURLsForURL "Find all known applications that are suitable for opening the item specified at the URL."

It seems that if you pass the file url you should get a list of applications (CFArrayRef).

+10
source share

In the future, I was interested to know a list of applications that can open a certain type of document. The accepted answer pointed in the right direction, but was not a complete solution as LSCopyApplicaionURLsForURL , and his brother LSCopyAllRoleHandlersForContentType returned the package identifier, not the application itself. So I still need the application:

  • Way
  • Display name; and
  • Pictogram

Below is the code I used to get all the 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]; } 
+9
source share

All Articles