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?
From the desktop, right-click the desired file. From the drop-down menu, click Open with, then select the desired application.
File Viewer is a FREE Android app that allows you to open and view files on your Android device. It supports over 150 file types and can display the contents of any file. You can use File Viewer's information panel to view hidden file details and metadata. Get File Viewer FREE from the Google Play store!
How does Windows know which application to use to open a file when you double-click the file in Windows Explorer? The file association between a data a file and an application is determined by the file extension. A program associated with a file extension is called its default program.
Associate one file with a specific program Right-click the file you want to change the file association and select Properties in the drop-down menu. In the file Properties, click the Change button next to the "Opens with" option.
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.
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];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With