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?
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.
LSCopyAllHandlersForURLScheme has been deprecated in 10.15
You can use LSCopyApplicationURLsForURL instead
LSCopyApplicationURLsForURL(URL(string: "https:")! as CFURL, .all)?.takeRetainedValue() as? [URL]
Also note, 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 App Name you can use
Bundle(url: fileURL)!.infoDictionary?["CFBundleDisplayName"]
and if CFBundleDisplayName
returns nil then CFBundleName
can be used
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