How to launch an app from Java in Mac OSX?

I would like to launch another application from my Java code which will run on OS X. Doesn anyone know how to do this? I think it involves the "Runtime.getRuntime.exec()" method, but I'm not sure how to tell it which application to launch.
Thanks

I dont know about OSX but i can give you a generalized
solution. In all OS's there will be a way to get to
command prompt. It is not really true: MacOS is one noticeable exception! Version 9, like every previous one, was completely extraneous to the notion of "command prompt", because the Macintosh, since its origin to nowadays, has been a "fanatically" User-Centric system: everything is iconic. A side effect of this approach is that MacOS was a pretty hard platform for low-level developers...
In MacOSX things have dramatically changed: this OS is a powerful Unix-like one, with the beautiful dress that only a Mac can wear: and finally, all you Mac users, here it is: the shell!
Of course, in MacOSX (and in MacOS "classic" too) there are paths and executable files.
MacOS1-9 file-system was a very peculiar one: resource fork and data fork for every file, ":" as path components separator (but what "common" user has ever seen a Macintosh path?) and so on.
MacOSX will use an Unix-like filesystem, I guess (I'm not a Mac user, I like every OS for its beauties - and therefore dislike Microsoft products even if often they give me bread).
But the key question is: how do I tell the runtime which file it has to execute?
Fortunately, every modern SO I know adopts a hyerarchical organization of its files. So, indipendently of what is considered the "root" ("C:\", "/" or whatever else), you can "trace" a relative path from your current path (if you use an Unix or URL idiom, "./") and the file you want to reach.
So, if your java app ("JavaApp.class") is placed in a folder called "MyJavaApp", nested in another folder called "Programs" that you see when you click on the "MacHD" icon, and you can manually launch the Mac app you're interested in clicking on an icon called "MyMacApp Program", placed in a folder called "MyMacApp", nested in another folder called "Programs" that you see when you click on the "MacHD" icon (it's the same folder we said before :-) ), using Unix or URL sintax we have that:
your java application is at: [...]/MacHD/Programs/MyJavaApp/JavaApp.class
the Mac application is at:
[...]/MacHD/Programs/MyMacApp/MyMacApp Program
The relative path from the former to the latter is, therefore:
../MyMacApp/MyMacApp
where two dots ("..") are the symbol for "parent folder".
If the situation is similar to above, the code to launch MyMacApp should be something like this:
import java.io.File;
File currentDir=new File("");
//supposing that double dot (..) is the symbol for "parent folder"
Runtime.getRuntime(
     new File(currentDir,".."
     +File.separator
     +"MyMacApp"
     +File.separator
     +"MyMacApp Program"
     ).getAbsolutePath()
in a more portable fashion - if you're not sure ".." works
(? who cares? we're launching a native app :-)) )
Runtime.getRuntime(
     new File(currentDir.getParent(),
     "MyMacApp"
     +File.separator
     +"MyMacApp Program"
     ).getAbsolutePath()
);Hope it works... good work!

Similar Messages

  • How do I move apps from an old mac to a new one

    I am purchasing a new Macbook Pro after having my old one for six years. I have numerous apps that I have purchased and downloaded over the years. I don't want to loose them and really don't want to have to purchase them again. Can I and how can I move apps from my old Mac to my new one?

    Be sure you back your current system up BEFORE you do anything. If you use Time Machine, migration assistant works well.
    Barry

  • How to launch an application from java?

    Hi,
    Would anybody please help me this. I need to launch a new desktop application from my java app but I don't know how. For example, when user clicks on a "Edit" button from my java app, my app needs to launch NOTEPAD.EXE to allow user starts editing.
    Thanks a lot.
    Hung.

    try something like this for your button's action method:
            String[] cmd = {"notepad"};
    Runtime rt = Runtime.getRuntime();
            try {
                Process pro = rt.exec(cmd);
                pro.waitFor();  // wait until it's done executing
                System.out.println("Process exit code is: " + pro.exitValue());
            }catch(IOException ioe) {
                System.err.println("IOException -> " + ioe);
            } catch(InterruptedException ie){
                System.err.println("InterruptedException: " + ie);
            }

  • How do you transfer apps from iPad to mac book pro?

    I need to upgrade to the ios5 on ipad I but it says I need to transfer the apps and I don't know how.

    There are purchased items on the iPad “Laura Crowell’s iPad” that have not been transferred to your iTunes library. You should transfer these items to your iTunes library before updating this iPad.
    This is the message I get...and I don't know how to transfer these to the iTunes library.  Perhaps this is my question??

  • How to execute Linux command from Java app.

    Hi all,
    Could anyone show me how to execute Linux command from Java app. For example, I have the need to execute the "ls" command from my Java app (which is running on the Linux machine), how should I write the codes?
    Thanks a lot,

    You can use "built-in" shell commands, you just need to invoke the shell and tell it to run the command. See the -c switch in the man page for your shell. But, "ls" isn't built-in anyays.
    If you use exec, you will want to set the directory with the dir argument to exec, or add it to the command or cmdarray. See the API for the variants of java.lang.Runtime.exec(). (If you're invoking it repeatedly, you can most likely modify a cmdarray more efficiently than having exec() decompose your command).
    You will also definitely want to save the returned Process and read the output from it (possibly stderr too and get an exit status). See API for java.lang.Process. Here's an example
    java.io.BufferedReader br =
    new java.io.BufferedReader(new java.io.InputStreamReader(
    Runtime.getRuntime().exec ("/sbin/ifconfig ppp0").
    getInputStream()));
    while ((s = br.readLine()) != null) {...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How do you launch an app from a shell?

    how do you launch an app from a shell?  how about an example... say, launch the texteditor app.

    To open an app from the terminal use the command open followed by the fullpath pf the command.
    So for TextEdit you would enter
    open /Applications/TextEdit.app

  • Launch another app from Siena app

    As it's not possible to launch a map in Siena, I'm hoping that I can pass an address out of Siena to the native Maps app in Windows 8. Is that possible? I can't find any documentation on how to open other apps from my app.

    Nice,
    Now we can launch browser, Skype, bing maps
    Sidenote: You need then to be sure that the user has the map app (or Skype) installed and all associations are correct. So at least best to write it in the prerequisites when moving to the app store.
    If you just want to add maps, you can also insert them directly in the app as static maps. I've explained that in
    http://social.technet.microsoft.com/Forums/en-US/45b2ffe3-4d57-4b4c-94a4-75d299a03e62/how-to-add-a-bing-map-with-pins-to-a-siena-project?forum=projectsiena
    The interactive nature is not present of course
    Or you could use the static google map api
    https://developers.google.com/maps/documentation/imageapis/
    Regards
    StonyArc
    http://www.stonyarc.com http://www.xboxlivenation.com

  • Help! How to convert an instance from java.lang.Object to a particula class

    * How to convert an instance from java.lang.Object class to a particular class
    witch is known only at the running time?
    Roster EJB component is make up of RosterHome, Roster and RosterBean.
    RosterHome is the home interface of Roster EJB.
    Roster is the remote interface of Roster EJB.
    RosterBean is the implement of Roster EJB.
    The following code segment is to invoke Roster EJB component.
    String jndiName="roster.RosterHome";
    javax.naming.Context initial = getInitialContext();//getInitialContext() returns a instance of Context.
    Object objref = initial.lookup(jndiName);
    RosterHome home =
    (RosterHome)javax.rmi.PortableRemoteObject.narrow(objref,
    RosterHome.class);
    Roster myRoster = home.create();
    String team="T1"
    String player="Tom"
    myRoster.addPlayer(player,team);
    But, now, all the home interface, the remote interface and the JNDI Name of
    Roster EJB component are not been known at the compiling time. However They are
    known at the running time, throught reading from the XML config file.
    Questions:
    1,How to write code for this case ? or
    2,How to convert an instance from Object class to a particular class witch is known
    only at the running time?
    String jndiName="roster.RosterHome";// in fact, reads from XML file.
    String homeClassName="roster.RosterHome";// in fact, reads from XML file.
    String remoteClassName="roster.Roster";// in fact, reads from XML file.
    javax.naming.Context initial = getInitialContext();//getInitialContext() returns a instance of Context.
    Object objref = initial.lookup(jndiName);
    Object objHome= javax.rmi.PortableRemoteObject.narrow(objref,
    Class.forName(homeClassName));
    /* how to do next?
    }

    I am not sure what you are trying to do. But at some point you should know which methods to call on the remote interfaces. Maybe the method names are stored in the XML file as well or you have a set of standard method names (also consider parameters).
    However, this can be solved by reflection. Look at the java.lang.reflect package, especially java.lang.reflect.Method, and also at java.lang.Class.
    If you are doing this on the app server:
    I've seen posts where people say that reflection is not permitted in EJB, but I don't think so. Check the EJB spec.
    If you are doing this in an application: reflection is always permitted. Probably also in applets and JSP.

  • How do I move apps from PalmOne Tungsten E2 to Palm TX?

    No device
    How do I move apps from PalmOne Tungsten E2 to Palm TX?
    Apps are:
    Blocks
    Big Clock
    Gobble
    YAUC
    Speed Value
    Mine Hunt

    Non-copywritten apps can be sent via BlueTooth ("Send"), or Infra-red ("Beaming").
    From the Launcher screen, tap the top left corner to open the pull-down menu.  Choose either Send or Beam, then select the program you want to transfer.
    To use BlueTooth, both devices should be paired first, and to use IrDA, you need to make sure "Beam Receive" is turned on in the receiving device.
    WyreNut
    I am a Volunteer here, not employed by HP.
    You too can become an HP Expert! Details HERE!
    If my post has helped you, click the Kudos Thumbs up!
    If it solved your issue, Click the "Accept as Solution" button so others can benefit from the question you asked!

  • How can I move apps from one computer to the other?

    How can I move apps from one computer to the other?
    (preferably without iCloud)

    Backup your iTunes library to an external drive and onto the other computer
    http://support.apple.com/kb/ht1751

  • How can i put apps from one ipod to a new ipod?

    how can i put apps from one ipod to a new ipod?

    iOS: Transferring information from your current iPhone, iPad, or iPod touch to a new device

  • How do I add apps from launchpad to my iPad

    I have a bunch of medical apps that I paid for and put them on my macbook pro.  I recently won an ipad at an office drawing and want to transfer the apps I would like to use for work from my macbook to my ipad and preferably keep them on both.  How can I tranfer apps from macbook to ipad?

    Sorry, apps designed for the Mac will not work on the iPad. There may be similar apps avaialble from the App Store that can be installed on the iPad.

  • How can i copy apps from one computer to another?

    how can i copy apps from one computer to another?

    You don't mention which operating system you have so it's difficult to provide an answer since the mac and Windows stores the files differently.
    The other thing you can do is just re-download the apps from the iTunes Store. Just login to the iTunes Store on the other computer using the same Apple ID. On the right-hand side of the iTunes Store page you will see a 'Purchased' link. Clicking on that will take you to a page that will list your past purchases which you can re-download to the new computer.

  • How can I transfer apps from one iTunes library to another?

    How can I transfer apps from one iTunes library to another? My daughter has an iTouch, and I was managing it through my library. I have created an iTunes account for her, with a new iTouch, and would like to move the apps over. I tried to sync the old iTouch to the new library and it said it was already set up to sync with a different library. What is the best way to do this?

    You can transfer iTunes purchases by:
    iTunes Store: Transferring purchases from your iPhone, iPad, or iPod to a computer
    To make the new computer the syncing computer you have to:
    - Transfer iTunes purchases lIke I described above
    - Make a backup of the iPod on that computer by connecting the iPod and then right-clicking on the iPod under Devices in iTunes and selecting Back Up.
    - Restore the iPOd from that backup
    She will have to continue to use your iTunes ID to update the apps prchased with your account. To use her account she will have to log into the computer with her account (iTunes>Store) and change the sign in on the iPod by going to Settings>Store.

  • How do I move apps from one page to another?

    How do I move apps from one page to another?

    From a previous thread:
    Touch and hold any icon for a couple of seconds. They'll all start to wobble. Touch and drag the one you want to move to the side of the screen and the next screen will appear; drop the icon on whatever screen you want it on.
    You can also do it quicker in iTunes - connect the phone and click the Apps tab in the main window. You'll see a picture of your phone with the apps laid out. Just click and drag

Maybe you are looking for

  • How to Back-Up an iPhoto Library to a Flash Drive in Mountain Lion

    I have been backing up my entire iPhoto library (about 34GB) to a flash drive every month for the last couple of years. I tried to do it last night, after upgrading to Mountain Lion, and could not complete the backup. I tried several times, and the s

  • HDMI with Xbox 360

    I just got an xbox 360 and i hooked it up to my imac with my eyetv hybrid. Can use the HDMI cables to make it High Def? What can i use to make it so it will hook up to the cables. thanks

  • Finder window shifts contents off screen to the left.

    On several occasions the window in my Finder shifts the contents off screen to the left. For example, in column view, the left most edge of the Finder window might be displaying files listed in column 2 or 3. And even that is only the rightmost slive

  • Using Numbers to shedule sort problem

    I am using Numbers to schedule the times that groups perform at an event I am organizing. If I make a time change to a group Numbers has also tagged this with the date of my entry and this affects the sorting. Is there a way to turn this off? I have

  • How much iPad memory do I need?

    I need an iPad for work, to compose music using an app, and surf the web. I don't plan on saving much music or photos on it and I'm not a video game player. Based on that, do I need any more memory than 16G?