Mounting a partition with AppleScript that has a space in the name

Discussion in 'OS X Mountain Lion (10.8)' started by alec6542, Apr 29, 2013.

  1. macrumors regular

    Jan 16, 2012
    Hi guys,

    I am trying to get this AppleScript I found online to work which is a quick way to mount unmounted volumes. For some reason, the script works just fine for any volume that is does not have a space in the name. For any that does (such as Macintosh HD in my case), I get an error message, which is in the screenshot below. I know the problem has to do with the space, because if I open terminal and run "diskutil mount Macintosh\ HD" (which the forward slash for space), the volume mounts just fine. But, if I try to put a forward slash in the Applescript, I get another error message. Here is both the script and the error message. In my case, "Media"

    Screen Shot 2013-04-29 at 11.12.56 PM.png

    Screen Shot 2013-04-29 at 11.12.37 PM.png

    Any help is appreciated. I did google this with several different search criteria and did not find a clear answer.
  2. thread starter macrumors regular

    Jan 16, 2012
    Anyone? I thought for sure this was a trivial issue.
  3. macrumors P6


    Jan 24, 2010
    It has to have two slashes, like this: "diskutil mount Macintosh\\ HD" The first is an escape for Applescript and the second is an escape for bash.
  4. macrumors newbie

    Oct 13, 2012
    Easier, I think, is to use 'quoted form of', ie:
    do shell script "diskutil mount " & quoted form of part
  5. macrumors newbie

    Aug 14, 2013
    Sonora, CA
    That is the best then you could be a little more free with your name spaces. ie if you would like your output to be...

    $sudo diskutil mount "/Volume/Some Drive/here"

    Then I would do the following.

    set volumeName to "/Volumes/Some Drive/here" as text
    do shell script "diskutil mount " & quoted form of volumeName with administrator privileges

Share This Page