8

How would one enumerate the installed browsers on an OS X system from a local app. I would like to build something like choosy, but different (long story). However, I would like to enumerate all installed browsers on the system.

On windows, I can dive the installed browsers in the Default Programs registries, however, I don't believe there is a similar concept on OS X. Do I have to manually search through all the bundles & their info.plist files?

3 Answers 3

11

Use LSCopyAllHandlersForURLScheme(CFSTR("http")) or LSCopyAllRoleHandlersForContentType(CFSTR("public.html"), kLSRolesViewer), or the set intersection of both.

Those two functions return bundle identifiers; you can use LSFindApplicationForInfo to find the preferred instance on disk of an application by its bundle identifier.

(Don't forget to follow the Core Foundation memory-management rules.)

Edit: In a comment on this answer, smorgan suggests LSCopyAllHandlersForURLScheme(CFSTR("https")) (that's https) as an alternative to the first call. This is a good suggestion.

3
  • I noticed these are Carbon APIs. I thought Carbon was being deprecated? May 31, 2009 at 4:51
  • 3
    Launch Services is part of Core Services, not Carbon. As such, it is not deprecated, and is available on 64-bit. (See the documentation: developer.apple.com/documentation/Carbon/Reference/… ) May 31, 2009 at 5:55
  • 2
    You might want to use "https" instead of "http", as in my experience the latter has more false-positives for things that are really browsers.
    – smorgan
    Jun 1, 2009 at 22:37
2

LSCopyAllHandlersForURLScheme has been deprecated in 10.15

You can use LSCopyApplicationURLsForURL instead

LSCopyApplicationURLsForURL(URL(string: "https:")! as CFURL, .all)?.takeRetainedValue() as? [URL]

Also, unlike LSCopyAllHandlersForURLScheme, LSCopyApplicationURLsForURL returns the URL of the file path of Applications.

You can then use Bundle(url: fileURL)!.bundleIdentifier to extract the bundleID

To extract the apps name you can use

Bundle(url: fileURL)!.infoDictionary?["CFBundleDisplayName"]

and if CFBundleDisplayName returns nil then CFBundleName can be used

1
  • 2
    looks like LSCopyApplicationURLsForURL is deprecated now too. What now?
    – luckman212
    Aug 8, 2021 at 16:19
0

Check this to list

NSArray* apps = (NSArray*)CFBridgingRelease(LSCopyAllHandlersForURLScheme(CFSTR("https"))) ;
NSLog(@"%@", apps);

This for default:

NSString* defaultBundleId = (__bridge NSString*)LSCopyDefaultHandlerForURLScheme(CFSTR("https"));
NSLog(@"default is %@", defaultBundleId);

Your Answer

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

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