We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › open() an application (mac)
Page Index Toggle Pages: 1
open() an application (mac) (Read 560 times)
open() an application (mac)
Apr 11th, 2006, 5:45pm
 
Hi,
I did an application which captures a webcam and I would like to run it from another file. So I have a GUI with a button, and whenever I click that button, the other processing (video-capturing) program should start. But open("thingy.app") delivers a JavaIOException. The applications are in the same sketch folder.
What am I doing wrong?
Re: open() an application (mac)
Reply #1 - Apr 12th, 2006, 2:44pm
 
use the absolute path to the .app, apple changed something in osx so that the current working directory for apps is now different.
Re: open() an application (mac)
Reply #2 - Apr 14th, 2006, 6:36am
 
hey i have a fix for this, a new open method for PApplet:


<code>
 public void open(String filename) {
   if (platform == WINDOWS) {
     // just launching the .html file via the shell works
     // but make sure to chmod +x the .html files first
     // also place quotes around it in case there's a space
     // in the user.dir part of the url
     try {
       Runtime.getRuntime().exec("cmd /c \"" + filename + "\"");
     } catch (IOException e) {
       e.printStackTrace();
       throw new RuntimeException("Could not open " + filename);
     }

   } else if (platform == MACOSX) {
     try {
// Java on OS X doesn't like to exec commands in " for soem reason
// escape spaces just in case
     if (filename.indexOf(' ') != -1) {
      StringBuffer sb = new StringBuffer();
      char c[] = filename.toCharArray();
      for (int i = 0; i < c.length; i++) {
        if (c[i] == ' ') {
          sb.append("\\\\ ");
        } else {
          sb.append(c[i]);
        }
      }
      filename = sb.toString();
     }

       Runtime.getRuntime().exec("open " + filename);
     } catch (IOException e) {
       e.printStackTrace();
       throw new RuntimeException("Could not open " + filename);
     }

   } else if (platform == MACOS9) {
     // prepend file:// on this guy since it's a file
     String url = "file://" + filename;

     // replace spaces with %20 for the file url
     // otherwise the mac doesn't like to open it
     // can't just use URLEncoder, since that makes slashes into
     // %2F characters, which is no good. some might say "useless"
     if (url.indexOf(' ') != -1) {
       StringBuffer sb = new StringBuffer();
       char c[] = url.toCharArray();
       for (int i = 0; i < c.length; i++) {
         if (c[i] == ' ') {
           sb.append("%20");
         } else {
           sb.append(c[i]);
         }
       }
       url = sb.toString();
     }
     link(url);

   } else {
     open(new String[] { filename });
   }
 }
</code>
Re: open() an application (mac)
Reply #3 - Apr 14th, 2006, 1:01pm
 
awesome, thanks for looking into it. now added for 0113.
Page Index Toggle Pages: 1