title: AppleScript: String and File Manpiulation
body: <p>After collecting a list of files with an mdfind() script, I now need to copy each of the files found and also to store their original paths for later. Essentially, I have to move a huge and widely distributed number of old AppleWorks files to a new volume, manually update them, and then replace the original files with new, updated versions <em>at the same locations and with the same filenames</em> (but not extensions or document type).</p>
  <p>As I am new to AppleScript, I am doing the file manipulation with Python and am only using AppleScript to locate the documents (as file extensions will not suffice for my purposes, I need to look at apple metatags via mdfind).</p>
  <p>But the document I can produce with my AppleScript—a list of file paths—is using the apple &quot;\r&quot; new line delimiter and consequently I cannot import this to python easily.</p>
  <p>My Apple Script:</p>
  <pre><code>set the_script to &quot;mdfind   kMDItemKind=='*AppleWorks*'&quot;
  set the_text to (do shell script the_script)
  set the_doc to (choose file)
  write the_text to the_doc
  </code></pre>
  <p>Which produces a .txt file with all sorts of lovely path names, but python reads it as one enormous string.</p>
  <p>How do I either</p>
  <p>a) tell Apple Script to append a custom delimiter to each line (ie. &quot;\n&quot;)</p>
  <p>or</p>
  <p>b) how do I tell Apple Script to copy each file it's found to a new location while preserving the original files and keeping a record of their paths?</p>
  <p>Any help would be much appreciated.</p>
  <p><strong>UPDATE  @Kindall</strong></p>
  <p>This is the error python throws when I try to pipe in the <code>mdfind</code> command:</p>
  <pre><code> File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
   File     &quot;/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py&quot;, line 679, in __init__
  errread, errwrite)
   File &quot;/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py&quot;, line 1228, in _execute_child
  raise child_exception
  OSError: [Errno 2] No such file or directory
  </code></pre>
  <p>Any ideas? I am primarily a web-developer trying to nub my way through some other languages to avoid manually sorting through 2-3k files on my bosses ancient mac laptop, haha (and I corrected the typographic errors in your original code, I am not trying to run it verbatim).</p>