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. When my text is written back to the CSV file it has lost all of its carriage returns, so it reads as one line. What am I doing wrong?
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
Any suggestions? The output of this code is:
1,2,3,A,B,C,X,Y,Z
when what I want is
1,2,3
A,B,C
X,Y,Z
theListvariable holds all the paragraphs (lines) of the original file as a list, so writing it to the file inside the loop will write the entire contents of the file as many times as you have lines. Perhaps it would make more sense to write to file after theend repeat?