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
내가 잘못하지 않았다면,'theList' 변수는 원래 파일의 모든 단락 (줄)을 목록으로 가지고 있으므로 루프 * 안에 파일 *에 쓰면 파일의 전체 내용 *을 쓸 것입니다 줄을 여러 번 가져라. 아마도'end repeat' * 후에 파일 *에 쓰는 것이 더 합리적일까요? – fanaugen