title: Writing a list to CSV using Applescript
body: <p>I have an applescript that reads data from a CSV (successfully!). After my script is done editing the data, I want it to write the modified text back to that file.
    <em>When my text is written back to the CSV file it has lost all of its carriage returns, so it reads as one line.</em> What am I doing wrong?</p>
  
  <pre><code>set theFile to choose file with prompt "Select a text file:"
  set theFileContents to read theFile
  ...
  
  
  set theList to paragraphs of theFileContents
  
  
  
  repeat with i from 2 to count theList
  
  set AppleScript's text item delimiters to ","
  set theLine to theList's item i
  theLine
  set clinic_id to first text item of theLine
  ....
  set AppleScript's text item delimiters to ""
  
  ...
  
      open for access theFile with write permission
  
      set theData to theList as text
      write the [theData] to theFile as text
      close access theFile
  
  
      display dialog the [theLine]
  end if
  end repeat
  </code></pre>
  
  <p>Any suggestions? The output of this code is:</p>
  
  <pre><code>1,2,3,A,B,C,X,Y,Z
  </code></pre>
  
  <p>when what I want is</p>
  
  <pre><code>1,2,3
  A,B,C
  X,Y,Z
  </code></pre>