cocoamacos

Enumerating installed browsers on OS X


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?


Solution

  • 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.