What do I configure the working directory of a set of MacOS applications running from my Java application?

advertisements

I've done some searching around both on this site and Google but haven't been able to find any information. I have a Java application that launches .app files in Mac OS. Now I understand that the .app extension is not really an executable but rather an application bundle which contains the executable in the "/Contents/MacOS/" sub directory.

For my example I'll use the app "/Applications/Chess.app". So in this case, the actual executable is located in "/Applications/Chess.app/Contents/MacOS/"

Is it simply just a matter of setting the working directory to be "/Applications/Chess.app/Contents/MacOS/"?


Mac apps generally can't rely on the working directory being set to anything in particular. Xcode sets it one way, launching from the Finder sets it a different way (usually to /).

However, you shouldn't run an app by just executing the binary in Contents/MacOS. You should use Launch Services or NSWorkspace (or, failing either of those, /usr/bin/open) to launch them.