Write to file= one long line

I understand how to write to a file, but I want to write many lines of text to a file. When I do this, it ends up as one huge line. How am I supposed to separate each line (with a new line) instead of having one enormous line?

Oddly, I’ve been working on stuff like that today:


write ("line 1" & return & "line 2" & return & "line 3")

That what you’re after?

I had notfications on, and right when I figured it out, you replied.

I have like 200 lines to write, so that wouldn’t be a very efficent way of doing it.

I did this:


tell application "iTunes"
	set numTracks to count of every track in current playlist
	set paths to location of every track in current playlist
	--set badPath to (get location of current track)
end tell
--
set num to 1
set AppleScript's text item delimiters to {return}
set goodPath to {}
--
set theFileID to open for access "Path:to:file.txt" with write permission
try
	repeat numTracks times
		set end of goodPath to POSIX path of item num in paths
		-- set goodPath to POSIX path of item num in paths
		set num to num + 1
	end repeat
	write (goodPath as text) & return to theFileID
end try
close access theFileID

There was a bit more to the script. It was a crude way of exporting the path of a bunch of tracks in a playlist in iTunes to a text file. There probably is a way of making it with less code, but this works well for what I have to do.

Well, I was stabbing in the dark…the short answer was using “& return” tacked onto every write, which basically “types” the return character. Which I think is what you basically have done.

:smiley:


set TID to AppleScript's text item delimiters
-- This part is just to get me a list of text lines --
set myLines to {}
repeat with k from 1 to 10
	set end of myLines to "This is Line " & k
end repeat

-- Now convert to text for writing -- this is the part you asked about
set AppleScript's text item delimiters to return
set myText to myLines as string
set AppleScript's text item delimiters to TID
-- write it out to a file
myText