PDA

View Full Version : Java in MAC OS




chidambaram
Apr 17, 2009, 04:57 AM
Hai,

I am trying to create a application file in mac, using the below code.



FileOutputStream fout;
try
{
fout = new FileOutputStream("/Users/laserwords/Desktop/fileopening.app");
new PrintStream(fout).println ("tell application \"Finder\" \n set myFil to \"Macintosh HD:sample1.pdf\" as string open file myFil \nend tell");
fout.close();
}
catch (IOException e)
{
System.err.println ("Unable to write to file");

System.exit(-1);
}

Above mentioned application file is created, But its type is, created as
Application (Classic).

So that file is, not executable.

If we manually create, it is working properly.

Can anyone help to resolve this?

Thanks in advance.



dr-jerry
Apr 17, 2009, 06:56 AM
How do you manually create it? I assume you need to set the umask to the file or even set some attributes to it.
Ast this is mac specific java may not be the right choice to create those files, as the option should also be avaible on windows.

plz ignore previous post as it was a matter of not reading the question..
j.

dr-jerry
Apr 17, 2009, 07:09 AM
Giving it a second or rather third thought:
grab a terminal, cd to the directory you're manuall creating the file in. And do a ls -l@ (assuming you're doing leopard).
You than need to figure out how to get java created file, have the same umask and attributes as the manually created file.
You than should use java.lang.Runtime to modify this file.
Hope this helps.

chidambaram
Apr 17, 2009, 07:23 AM
I open the script editor, Typed this

tell application "Finder"
set myFil to "Macintosh HD:sample1.pdf" as string
open file myFil end tell

Saved this as,
fileopen.app


If i double click the file "fileopen.app", it will open ,sample1.pdf

it is just like a bat file in Windows.

wrldwzrd89
Apr 17, 2009, 07:32 AM
Hai,

I am trying to create a application file in mac, using the below code.



FileOutputStream fout;
try
{
fout = new FileOutputStream("/Users/laserwords/Desktop/fileopening.app");
new PrintStream(fout).println ("tell application \"Finder\" \n set myFil to \"Macintosh HD:sample1.pdf\" as string open file myFil \nend tell");
fout.close();
}
catch (IOException e)
{
System.err.println ("Unable to write to file");

System.exit(-1);
}

Above mentioned application file is created, But its type is, created as
Application (Classic).

So that file is, not executable.

If we manually create, it is working properly.

Can anyone help to resolve this?

Thanks in advance.
The problem is that AppleScripts aren't plain text, but rather a cryptic binary format.

chidambaram
Apr 17, 2009, 07:36 AM
Thanks for your reply,

is it possible to change plain text into cryptic binary format.

So that it will be executable....

mufflon
Apr 17, 2009, 07:38 AM
the best alternative would be to download eclipse or netbeans, import the code and then export it as a runnable jar file with the main entry point to be the file you defined your "public static void main"... ... it'll be a .jar and not a .app, but it will do the trick and work just as well.

chidambaram
Apr 17, 2009, 07:46 AM
Hi,

Thanks for ur reply.

Actually my requirement to open a pdf file using java program. I installed netbeans in my Mac Machine.

Without using this type of batch file ,can i open that file in any other way?

kainjow
Apr 17, 2009, 08:22 AM
Use /usr/bin/open:
open -a ~/Desktop/fileopening.app /sample1.pdf