Applescript creating Sym link with spaces in the path

I'm trying to create a sym link to a network directory when i log in. This is working for a couple of other directories without spaces in the name, but for the life of me I cannot get this one director to work and I'm assuming it has to do with the space characters.

in a terminal window I can successfully create the link manually with

ln -s "/Volumes/D/Contracts and Price Sheets"/ ~/Desktop/Contracts

my current applescript looks like this

tell application "Finder"
  mount volume "smb://user:[email protected]/D"
  set contractsPath to "/Volumes/D/Contracts and Price Sheets/"
  if not (exists ((path to desktop as text) & "hDrive")) then
    do shell script "ln -s /Volumes/D/Home/user/ ~/Desktop/hDrive"
  end if
  if not (exists ((path to desktop as text) & "sDrive")) then
    do shell script "ln -s /Volumes/D/Data/ ~/Desktop/sDrive"
  end if
  if not (exists ((path to desktop as text) & "Inventory")) then
    do shell script "ln -s /Volumes/D/Inventory/ ~/Desktop/Inventory"
  end if
  if not (exists ((path to desktop as text) & "Contracts")) then
    do shell script "ln -s " & quoted form of the POSIX path of contractsPath & " ~/Desktop/Contracts"
  end if
end tell

I'm sure all these conditionals are bad habit, but I'm not an experienced programmer. Anyway, the first three drives mount successfully, however the final directory (with spaces in the title) just will not work. I've combed the web for answers, but keep getting no results.

Any and all input is greatly appreciated. Thanks!


Solution 1:

Hm, I've run a similar script in AppleScript Editor but it works ok for me:

set contractsPath to "/Users/subhu/Test test test/"
do shell script "ln -s " & quoted form of the POSIX path of contractsPath & " ~/Desktop/test"

Note that, if you escaping a backslash with another backslash you have to use just contractsPath, not quoted form of the POSIX path of contractsPath, e.g.:

set contractsPath to "/Users/subhu/Test\\ test\\ test"
do shell script "ln -s " & contractsPath & " ~/Desktop/test"

Try it.