Apple Script "spaces' syntax

Discussion in 'Mac Programming' started by mishamazor, Oct 31, 2011.

  1. mishamazor macrumors newbie

    Joined:
    Dec 23, 2007
    #1
    Trying to launch an app remotely thru ssh. Everything works, except my application name has spaces in it and I'm getting an Apple Script error on the syntax of the "open -a NET\ Render\ Client" string. How do I launch my "Net Render Client.app" with a script via Terminal?

    Code:
    tell application "Terminal"
        activate
        my execCmd("ssh me@hocalhost", 1)
        my execCmd("myPassw0rd", 0)
        my execCmd("open -a NET\ Render\ Client", 1)
        my execCmd("exit", 0)
    end tell
    on execCmd(cmd, wait)
    tell application "System Events"
        tell application process "Terminal"
        set frontmost to true
        keystroke cmd
        keystroke return
        end tell
    end tell
    delay wait
    end execCmd
    Thanks!
    Misha
     
  2. Partron22 macrumors 68000

    Partron22

    Joined:
    Apr 13, 2011
    Location:
    Yes
    #2
    I made a copy of TextEdit in my App folder, just so this script could open it.
    Notice that its name contains a space. The 'quoted form' bit takes care of the problem

    Code:
    set apfolderpath to POSIX path of (path to applications folder as text)
    set z to quoted form of (apfolderpath & "TextEdit copy.app")
    
    do shell script "open " & z
    TN2065 should clarify things 'do shell script', 'quoted form', and 'POSIX path' for you:
    do shell script in AppleScript
     
  3. mishamazor thread starter macrumors newbie

    Joined:
    Dec 23, 2007
    #3
    Problem solved

    Double backslash did the trick:

    Code:
    tell application "Terminal"
        activate
        my execCmd("ssh me@hocalhost", 1)
        my execCmd("myPassw0rd", 0)
        my execCmd("open -a NET\\ Render\\ Client", 1)
        my execCmd("exit", 0)
    end tell
    on execCmd(cmd, wait)
    tell application "System Events"
        tell application process "Terminal"
        set frontmost to true
        keystroke cmd
        keystroke return
        end tell
    end tell
    delay wait
    end execCmd
     

Share This Page