Read from file into a list

I want to use a text file as an external source for info. I want to read the into my script, setting each line of the text file to an item in a list. I’ve tried a couple things and am not having any luck. Can anyone give me some help?
Thanks in advance, Dave

: I want to use a text file as an external source for info. I want to read the
: into my script, setting each line of the text file to an item in a list.
: I’ve tried a couple things and am not having any luck. Can anyone give me
: some help?

: Thanks in advance, Dave

Try this:

 set theList to (read fileID as {text} using delimiters {return})

Marc K. Myers
Marc@AppleScriptsToGo.com
AppleScriptsToGo
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074

[5/1/02 11:09:54 PM]

: This worked as far as reading in the info and setting my var. to that info,
: but I’m still having the problem of getting it to see each line as a
: seperate item of the list. It’s lumping them all together as a single
: item.
: Dave
Ahh sorry…I missed the subtle difference between the ( and { I tried it again…It worked! Thanks much for your help! Dave

: Try this:

 set theList to (read fileID as {text} using delimiters
: {return})
 Marc K. Myers  Marc@AppleScriptsToGo.com >
: AppleScriptsToGo
: 4020 W.220th St.
: Fairview Park, OH 44126
: (440) 331-1074
: [5/1/02 11:09:54 PM]

This worked as far as reading in the info and setting my var. to that info, but I’m still having the problem of getting it to see each line as a seperate item of the list. It’s lumping them all together as a single item.

Dave

: This worked as far as reading in the info and setting my var. to that info,
: but I’m still having the problem of getting it to see each line as a
: seperate item of the list. It’s lumping them all together as a single
: item.

I assumed that each line ends with a carriage return and so used a return as the delimiter. You’ll have to determine what the actual delimiter is and replace “return” in the code with it. If there are no delimiters then there is no way to discern where one line ends and another begins.
Marc K. Myers
Marc@AppleScriptsToGo.com
AppleScriptsToGo
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074

[5/2/02 12:43:11 PM]

: You are correct, each line ends with a carriage return.
: Example…
: 1/23/2002
: 4/5/2002
: 4/19/2002
: but when I read in using your example it ends up as…
: 1/23/20024/5/20024/19/2002

I plugged your three lines into a text file and proceeded as follows:

set theList to (read file "Macintosh HD:Desktop Folder:testFile" as {text} using delimiter {return})

→ {“1/23/2002”, “4/5/2002”, “4/19/2002”}
How is mine different from yours?
Marc K. Myers
Marc@AppleScriptsToGo.com
AppleScriptsToGo
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074

[5/3/02 1:07:41 AM]

: I assumed that each line ends with a carriage return and so used a return as
: the delimiter. You’ll have to determine what the actual delimiter is and
: replace “return” in the code with it. If there are no
: delimiters then there is no way to discern where one line ends and another
: begins.
Marc K. Myers < Marc@AppleScriptsToGo.com >
: AppleScriptsToGo
: 4020 W.220th St.
: Fairview Park, OH 44126
: (440) 331-1074
: [5/2/02 12:43:11 PM]

You are correct, each line ends with a carriage return.

Example…

1/23/2002
4/5/2002
4/19/2002

but when I read in using your example it ends up as…
1/23/20024/5/20024/19/2002