DyreSchlock
DyreSchlock

Reputation: 873

Opening more than one of the same Mac Application at once

I'm developing a Mac App in Java that logs into any one of our client's databases. My users want to have several copies of this program running so they can log into a couple clients at the same time, rather than logging out and logging back in.

How can I allow a user to open several copies of my App at once?

I'm using Eclipse to develop, and Jarbundler to make the app.

Edit: More Importantly, is there a way to do so in the code base, rather than have my user do something funky on their system? I'd rather just give them a 'Open New Window' menu item, then have them typing things into the Terminal.

Upvotes: 1

Views: 825

Answers (4)

Josh Gagnon
Josh Gagnon

Reputation: 5351

You've probably already gotten enough code that you don't want to hear this, but you should really not be starting up two instances of the same application. There's a reason that you're finding it so difficult and that's because Apple doesn't want you to do it.

The OSX way of doing this is to use the Cocoa Document-based Application template in XCode. Apple Documentation: choosing a project.

This is something users are very accustomed to, and it works just fine. FTP programs, IRC clients, and many other types already use different "document" windows to point to different servers or channels. There's nothing inherently different about pointing to different databases.

Depending on how much code you've written, and how your application is designed, this may be pretty much impossible to implement without starting over. Developers who are encountering this problem during design phase, however, should definitely take Apple's advice.

Upvotes: 4

Joshua
Joshua

Reputation: 26752

If you are developing it in swing, you should just be able to instantiate the top Frame to create a new window.

Upvotes: 0

wprl
wprl

Reputation: 25447

From the Terminal (or in a script wrapper):

/Applications/TextEdit.app/Contents/MacOS/TextEdit  &

Something like that should work for you.

To do this in Java:

 String[] cmd = { "/bin/sh", "-c", "[shell commmand goes here]" };
 Process p = Runtime.getRuntime().exec (cmd);

Upvotes: 0

DyreSchlock
DyreSchlock

Reputation: 873

From the Terminal, I can run

open -n -a appName.app

Then from Applescript, I can run

tell application "Terminal"
activaate
   do script "open -n -a appName.app"
end tell

Then from Java, I can execute that script. Then, I can stuff that Java code into an Action. Then, stuff that action into a menu item that says "Open New Window".

That's what I'm going with for the moment. Now I just need to get the appName.

Upvotes: 0

Related Questions