I'm writing a cross-platform Python application that acts as a frontend for DOSBox. It needs to call the DOSBox executable with a number of command line arguments. I don't want to hardcode a specific path to DOSBox because it might depend on where the user has installed it.
On Linux, I can simply do:
import subprocess
subprocess.run(['dosbox'] + args)
On macOS, however, I currently use the following code:
import subprocess
subprocess.run(['/Applications/dosbox.app/Contents/MacOS/DOSBox'] + args)
Which seems awfully specific and I'm not even sure whether it works, since I don't have a mac to test on.
What is the correct way to open an application by name on macOS?
(NB: I have also asked this sibling question for Windows.)