executeProgramInBackground in Mac OS X

I want to open a program under Mac OS X. This is fairly straight forward in Windows, but I cant get it to work on the Mac.

Sample code:

application.executeProgramInBackground('/Applications/TextMate.app');

When running this code I get the error:

java.io.IOException: /Applications/TextMate.app: cannot execute

Help appreciated.

Servoy Developer
Version 3.5-build 513
Java version 1.5.0_07-87 (Mac OS X)

I think you have to figure out where the app really is. You’re now executing the directory. Under Mac OS X most apps are actually a directory to hide the actual files from the end user… eg TextEdit.app is opened like this:

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

Is there an easy way to open a file in its native app on OS X (or Windows for that matter) without knowing the path to the “real” app?

What I am aiming to do is give the user the ability to open a file stored in the database (such as a word file for instance) in its native app. Obviously I can write the file to a temp location, but what is the easiest way to open it in its app?

With Windows I can have a user define a set of preferences to get the path to the .exe file and then use that in conjuction with the above function, but, with what you say about OS X, this would more difficult to do.

create a global method: openFile()

var tmpfile = arguments[0]
//windows
if(utils.stringMiddle(application.getOSName(),1,7) == "Windows") 
{ 
   application.executeProgram('rundll32', 'url.dll,FileProtocolHandler',tmpfile) 
}
//FreeBSD or Linux
else if(utils.stringMiddle(application.getOSName(),1,7) == "FreeBSD"||utils.stringMiddle(application.getOSName(),1,5) == "Linux") 
{ 
   application.executeProgram('mozilla', tmpfile) 
}
//Mac OSX
else if(application.getOSName().match("Mac")) 
{ 
   application.executeProgram('open', tmpfile) 
}

than do this: globals.openFile(‘c:\test.doc’)

Hope this helps.

Thanks Harjo, works like a charm!