1

In the finder, a user can right click / "open with" and see a list of applications that can be used to open the file.

How can I get this list of applications programmatically?

ObjC or Python preferred, but also curious if there's a command line utility that exposes this functionality.

1 Answer 1

1
NSArray *applicationURLs = CFBridgingRelease(LSCopyApplicationURLsForURL((__bridge CFURLRef)fileURL, kLSRolesAll));
NSLog(@"applicationURLs %@", applicationURLs);

// Output

applicationURLs (
    "file:///Applications/calibre.app/",
    "file:///Applications/Archiver.app/",
    "file:///Applications/Pacifist.app/",
    "file:///System/Library/CoreServices/Archive%20Utility.app/"
)

For default app:

   CFURLRef defaultApplicationForURL = NULL;
   LSGetApplicationForURL((__bridge CFURLRef)fileURL, kLSRolesAll, NULL, &defaultApplicationForURL);
   NSLog(@"deafultApplicationForURL %@", defaultApplicationForURL);

// Output

deafultApplicationForURL file:///System/Library/CoreServices/Archive%20Utility.app/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.