Skip navigation

Spaces in shell script application?

503 Views 7 Replies Latest reply: Feb 3, 2013 8:30 AM by red_menace RSS
MacMan240 Level 1 Level 1 (80 points)
Currently Being Moderated
Feb 3, 2013 7:38 AM

how do I signify a space in the application name in the following script:

 

do shell script "/Applications/Plex Media Server.app/Contents/MacOS/Plex Media Scanner -s -r"

 

Screen Shot 2013-02-03 at 10.37.56 AM.png

MacBook Pro, OS X Mountain Lion (10.8.2), 2.3 GHz i5, 4GB RAM, OCZ 120GB SSD
  • Niel Level 10 Level 10 (235,110 points)
    Currently Being Moderated
    Feb 3, 2013 7:54 AM (in response to MacMan240)

    Use:

     

    do shell script "'/Applications/Plex Media Server.app/Contents/MacOS/Plex Media Scanner' -s -r"

     

    or:

     

    do shell script "/Applications/Plex\\ Media\\ Server.app/Contents/MacOS/Plex\\ Media\\ Scanner -s -r"

     

    (75942)

  • red_menace Level 6 Level 6 (14,315 points)
    Currently Being Moderated
    Feb 3, 2013 7:54 AM (in response to MacMan240)

    You can escape spaces in the path with a backslash, but since the backslash is also the escape character you need to escape it as well, so you wind up with:

    /Applications/Plex\\ Media\\ Server.app/Contents/MacOS/Plex\\ Media\\ Scanner

     

    Usually it is easier to use quoted form of, and let the system figure it out:

     

    set somepath to quoted form of "/Applications/Plex Media Server.app/Contents/MacOS/Plex Media Scanner"

    do shell script somepath & " -s -r"

  • Niel Level 10 Level 10 (235,110 points)
    Currently Being Moderated
    Feb 3, 2013 8:13 AM (in response to MacMan240)

    Here:

     

    tell application "System Events"

    set is_running to exists process "Plex Media Server"

    end tell

     

    (75948)

  • Niel Level 10 Level 10 (235,110 points)
    Currently Being Moderated
    Feb 3, 2013 8:28 AM (in response to MacMan240)

    Use:

     

    tell application "System Events"

    set is_running to exists process "Plex Media Server"

    end tell

    if is_running then

    do shell script "'/Applications/Plex Media Server.app/Contents/MacOS/Plex Media Scanner' -s -r"

    else

    display alert "Please start the server first"

    end if

     

    (75955)

  • red_menace Level 6 Level 6 (14,315 points)
    Currently Being Moderated
    Feb 3, 2013 8:30 AM (in response to MacMan240)

    Check if that is really the process name - the process name can be different than the application name.

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.