Can't read filecontents in repeat loop

I made this script to replace the items in a comma separated file, which was exported from Xcel. It must be flexible for the count of lines.
Problem is it reads the first line perfectly but it won’t read the line itself using delimiter ;
It says that it can’t make the data of this into a file
It doesn’t make sense to me. Anyone else?
Have a look and shoot…

I’m not quite sure I follow what you are trying to do but I suspect this is close to what you want:

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Hi,

When I make a text file with TextEdit and try to read it in as a list using delimiter ‘return’, it doesn’t work. It’s something to do with the line endings. If I wirte the file with AppleScript (standard additions), then it works. For example, write a text file:

set the_text to "hello
goodbye
zoo
monkey
turtle
verify
hacienda
aloha
"
set desk_ref to (path to desktop) as string
set file_spec to (desk_ref & “My File”) as file specification
set ref_num to (open for access file_spec with write permission)
try
write the_text to ref_num
close access ref_num
on error err_mess
close access ref_num
display dialog err_mess buttons {“OK”} default button “OK”
error number -128
end try
beep 3
tell application “Finder” to activate
activate

Now read the file using delimiter (a list):

set the_file to (choose file)
set cr to return
set ref_num to (open for access the_file)
try
set the_result to (read ref_num using delimiter cr)
close access ref_num
on error err_mess
close access ref_num
display dialog err_mess buttons {“OK”} default button “OK”
error number -128
end try
the_result

Apple needs to do something about these line endings.

gl,

The problem isn’t purely with AppleScript. There are a number of errors in your script which is compounding the problem.

For example, you say:

which would be OK, except that you previously defined line_:

BZZZZT. The ‘read’ command takes a file reference and reads the contents of that file. In this case line_ is a line of text from the file, so you’re trying to read a line instead of a file.
I wouldn’t expect the rest of the script to make any sense given that this line isn’t going to return what you expect.

As for the line endings issue, the simplest solution is to be flexible in your handling of it - don’t assume returns or line feeds, just let AppleScript do all the work.

The following code will read a file into a list of lines whether the file is cr or lf-delimited:

set theLines to paragraphs of (read file "path:to:file")

‘paragraphs of’ is smart enough to handle both types of line endings.

Hi,

I’m not trying to cover up the problem.

gl,