Hi all,
I’m having a problem writing a script to read a text file to get a list of numbers which I will then use to search for Quark ads on a server. I have the text worked to do the find but can’t get the coding right for reading the file.
My code for reading the file:
set theFile to alias ((path to desktop as string) & “JobAdList”)
set fref to (open for access theFile)
set tsize to (get eof theFile)
read fref using delimiter {“,”} as string from 1 to tsize
close access fref
display dialog fref
This might work, assuming that the text file contains something along the lines of: 101,202,303,404
set theFile to alias ((path to desktop as string) & "JobAdList")
set num_list to (read theFile using delimiter ",")
repeat with num in num_list
-- Quark code
end repeat
I’ve tested the code in OS X 10.2.8 (AppleScript v1.9.1) and OS 9.1 (AppleScript v1.8.3) and it works as expected (produces a list of numbers). I don’t have access to a machine running the versions that you are running so hopefully someone else will offer a fix.
My first thought is that the ‘open for access’ and ‘close access’ commands are almost never needed, as the ‘read’ command will automatically open a file for reading and then close it if it wasn’t previously opened. My second thought is that it isn’t nessesary to specify the reading start and end since your reading the whole file. My third thought is that you are mistaking the file reference number as a variable containing text, ie: you have to set the result of the ‘read’ command to a variable.
set numberList to read (theFile) using delimiter {","}
return result --> {"4", "10", ...}
My final thought is that Apple needs to update its documentation, not only for the language itself, but also for all commands in Standard Additions.