What do I set the working directory of a MacOS app bundle launched from my Java app?

Go To StackoverFlow.com

2

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/"?

2012-04-04 16:53
by drumhead
Did you try Desktop.getDesktop().open("/Applications/Chess.app")a_horse_with_no_name 2012-04-04 17:35
Yes that is what I currently have in my code and it works fine. However I thought that there may be apps that I launch that might need to have the correct working directory specified. For example, my Java app also launches .exe files on Windows and certain Windows applications only work when the working directory is set to that of the location of the .exe file. So I figured that with MacOS, I might run into the same issue - drumhead 2012-04-04 17:57


1

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.

2012-04-04 17:30
by Ken Thomases
On your second point, could i ask why? I find that by executing the binary in Contents/MacOS I can (from a terminal for example) read any output directly in the terminal. I sympathise that this feels wrong, although i'm curious to know what the downsides are - wardw 2017-03-06 16:03
@wardw: That's fine. The OP was talking about having one app launch another that way for the user's sake. An app shouldn't do that; it should use launch services. For example, users generally don't expect there to be multiple running instances of an app. Launch Services will avoid that (activating the already-running instance instead), while it's easy to accidentally do that if you run the executable directly - Ken Thomases 2017-03-06 16:34


0

I use "$APP_PACKAGE/Contents/..." [value] under the "WorkingDirectory" [key] set in string mode under [dictionary] "Java". Hope this helps.

I'm trying to change the location by user so I've been there the only problem is that the size of your app will increase exponentially but never decrease even if you delete all the contents so I'm trying to work out side of it tell me how it goes. Luck to you.

2013-08-07 22:01
by Brandon Roehl
Ads