tags:

views:

42

answers:

1

Is there a reasonable way to execute a .app directory directly from Java instead of digging down to find the binary? I've got an app with some preferences that include external programs for opening various things, it'd be nice if on OSX the user could just select the .app folder. I could look for the .app extension and handle it differently if necessary.

+3  A: 

You can simply call "open appname.app" in the Terminal. So ... Runtime.getRuntime().exec("open path.app") should work fine.

Milan Ramaiya
Sure enough, didn't realize exec passed commands through the terminal. Thought it loaded the binary directly.
gct
Good answer, I'd recommend always using the exec method which takes a String[] as arguments, it will avoid some odd behavior when the app has special characters in the name.Also, if you want to open a specific file with a given OS X app, use the -a argument. e.g.Runtime.getRuntime().exec(new String[] { "open", "path/to/file", "-a", "BBEdit"});
Sam Barnum
@gct strictly speaking it's through the *shell*, not the terminal.
finnw