PDA

View Full Version : calling applescript from java




confusion
Jun 11, 2006, 01:17 PM
hello everybody,

i have a java application, that should mount a smb-drive via applescript.

i use the following code:

...
StringBuffer script = new StringBuffer();
script.append("\'tell application \"Finder\" to mount volume \"smb:/");
script.append(ip);
script.append("/MyShare\"\'");
String[] cmd = {"osascript", "-e", script.toString()};
try {
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(cmd);
...

but it doesn't work. an error is written to stderr

0:1: syntax error: A unknown token can't go here. (-2740)

if i print script and copy-paste it to the terminal it works as expected...

what am I doing wrong?

confusion



jeremy.king
Jun 12, 2006, 03:16 PM
Any reason you are not using the NSAppleScript class?

http://www.macdevcenter.com/pub/a/mac/2003/02/25/apple_scripting.html

Don't know for sure, but do you need an "end tell" in there?

kainjow
Jun 15, 2006, 03:13 PM
Any reason you are not using the NSAppleScript class?

http://www.macdevcenter.com/pub/a/mac/2003/02/25/apple_scripting.html

Don't know for sure, but do you need an "end tell" in there?
NSAppleScript is the way to go.

And he doesn't need an "end tell" because he's using "tell application X to do something". The "to" makes it more sentence-like..