title: Replacing spaces in filename to pass to Clipboard with applescript
body: <p>I am working on a script to have Finder get a file's location locally, replace spaces with %20, then append localhost:// so the transformed file name can be inserted into email.</p>
  
  <p>I've have used the replacing spaces code structure suggested elsewhere on stackoverflow but the code is coming up with error 1721. I am not sure what I've done wrong.</p>
  
  <p>The code for text substitution is:</p>
  
  <pre><code>on run {input, parameters}
      set newString to {"localhost://"}
      set aString to "/file name input/"
      set aString to aString as text
      set charToReplace to " "
      set newChar to "%20"
      repeat with i in aString
          if (i as string) is charToReplace then
              set end of newString to newChar
          else
              set end of newString to (i as string)
          end if
      end repeat
      return input
  end run
  </code></pre>
  
  <p>The output should be /file%20name%20input/</p>
  
  <p>Thanks for any help you can offer.</p>
  
  <p>Michael</p>