Detection of installed web browsers on Mac OS

Platform: macOS, Sonoma 14.6 Technology stack: Electron v29, TypeScript

Hello,

We're developing a desktop app for macOS that helps with automation of some browser related tasks, using Puppeteer and Chrome/Chromium browsers. One of the conditions of our app running is having Chrome/Chromium installed on the computer.

To check if someone has installed one of the supported browsers our app runs the following command in the shell:

mdfind "kMDItemKind == \'Application\'"

it produces the list of installed apps and then we scan the list in the search of Chrome or Chromium.

Recently we found out that the command's result is not consistent, because on some macOS computers the result is empty and we don't know why.

Are we misunderstanding the usage of mdfind? Or maybe we should try a different way to check if Chrome or Chromium is installed on the computer running our app?

Thank you.

Answered by DTS Engineer in 806539022
Are we misunderstanding the usage of mdfind?

Yes. In general, command-line tools are intended to be used by (advanced) users and you shouldn’t use them as API… unless there’s no alternative. In this case there are two alternatives:

  • The APIs that let you access the Spotlight database

  • The APIs that let you access the Launch Services database

IMO the latter is better for your use case because the Launch Services database specifically tracks apps. The easiest way to access the LS database is via NSWorkspace. If, for you example, you know the bundle ID of the app you’re interested in, you can use urlsForApplications(withBundleIdentifier:) method to find all known instances of that app.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Are we misunderstanding the usage of mdfind?

Yes. In general, command-line tools are intended to be used by (advanced) users and you shouldn’t use them as API… unless there’s no alternative. In this case there are two alternatives:

  • The APIs that let you access the Spotlight database

  • The APIs that let you access the Launch Services database

IMO the latter is better for your use case because the Launch Services database specifically tracks apps. The easiest way to access the LS database is via NSWorkspace. If, for you example, you know the bundle ID of the app you’re interested in, you can use urlsForApplications(withBundleIdentifier:) method to find all known instances of that app.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thanks, we will try to make a native call to the AppKit from our Electron app and use the urlsForApplications method for Chrome detection. We will let you know if further assistance is required. :)

Detection of installed web browsers on Mac OS
 
 
Q