How to programmatically open an application by name on macOS?

I don't know DOSBox or want it on my Mac, but in general, when you install an application on macOS it has a "property list" file, or plist or "info.plist" in it. In there, the developer is supposed to put a "bundle identifier" key called CFBundleIdentifier. This must be unique across all applications, so for DOSBox it should be something like:

<key>CFBundleIdentifier</key>
<string>com.dosboxinc.dosbox</string>

Get one of your users to find that, then you can use the bundle identifier to open it like this regardless of installation location:

open -b BUNDLEIDENTIFIER --args arg1 arg2 arg3

where arg1, arg2 and arg3 get passed on to DOSBox.


You may be able to get the bundle identifier by running this in Terminal:

osascript -e 'id of app "DOSBox"'

Note, however, that if this command works, it means I have correctly guessed the app name "DOSBox", which means that you could just use the app name with open, rather than the bundle identifier like this:

open -a DOSBox --args arg1 arg2 arg3

Tags:

Python

Macos