Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enumerating installed browsers on OS X

Tags:

macos

cocoa

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?

like image 464
Dominic Hopton Avatar asked May 31 '09 04:05

Dominic Hopton


2 Answers

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.

like image 182
Peter Hosey Avatar answered Oct 26 '22 08:10

Peter Hosey


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

like image 37
Kaunteya Avatar answered Oct 26 '22 08:10

Kaunteya