2
我有一个从CSV读取数据的applescript(成功!)。在我的脚本完成编辑数据后,我希望它将修改后的文本写回该文件。 当我的文本被写回到CSV文件时,它已经失去了所有的回车,所以它读取为一行。我做错了什么?使用Applescript将列表写入CSV
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
有什么建议吗?这段代码的输出是:
1,2,3,A,B,C,X,Y,Z
当我要的是
1,2,3
A,B,C
X,Y,Z
如果我没有弄错,'theList'变量将原始文件的所有段落(行)保存为一个列表,因此将它写入循环*内的文件*将写入文件的*整个内容*尽可能多的你有线。在'end repeat' *之后写入文件*可能更有意义? – fanaugen 2012-04-11 07:58:26