calling applescript from java

Discussion in 'Mac Programming' started by confusion, Jun 11, 2006.

  1. macrumors newbie

    Joined:
    Jul 15, 2003
    Location:
    Basel/Switzerland
    #1
    hello everybody,

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

    i use the following code:

    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

    Code:
    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
     
  2. macrumors 603

    jeremy.king

    Joined:
    Jul 23, 2002
    Location:
    Fuquay Varina, NC
    #2
  3. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #3
    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..
     

Share This Page