Re: Strange Error Reading File
Re: Strange Error Reading File
- Subject: Re: Strange Error Reading File
- From: David Crowe <email@hidden>
- Date: Mon, 5 Apr 2004 08:51:53 -0600
Nigel;
Thanks for your message. I was confused about the behaviour of the
"error" statement.
But I still don't understand the end of file error.
It's not a timing issue because if the file is bad I can read it a
second time and get the same error. And it's a mystery because if I
download it again it almost always works and a comparison shows that
the files are identical.
It's something I can live with, but it's annoying because it was a
previously reliable script and this just started happening.
- David
Message: 1
Subject: Re: Strange error reading file...
Date: Sun, 4 Apr 2004 12:51:31 +0100
From: Nigel Garvey <email@hidden>
To: "AppleScript Users" <email@hidden>
David Crowe wrote on Sat, 3 Apr 2004 11:47:39 -0700:
I am having strange errors reading small text files with Applescript.
The code in question is:
set ImportFileRef to open for access AFile
-- Read all lines from file
set i to 0
try
set Filecontents to read ImportFileRef
on error errmsg number errnum
error errmsg number errnum
end try
I get an error on the "error" statement!
The word "errmsg" (second occurrence) is highlighted by the Script
Editor and a dialog box pops up:
"AppleScript Error
End of file error"
That's because the action you're taking in the 'on error' section is
simply to regenerate the error you've just trapped. Ideally, you should
be displaying an explanatory dialog here and/or tying up any loose ends -
such as closing the file. Script Editor doesn't always highlight the
exact *word* where an error occurred, but here it's correctly
highlighting the deliberate error rather than the original one.
The most common cause that I know of for an "End of file" error when
reading an entire file is that the file has been read through to the end
and then not closed on a previous run. But given your description of the
circumstances and the fact that you're using an 'open for access'
reference (which would tend to shield you from the error), it seems
likely that there's nothing actually in the file the first time you try
to read it. Either it's being created by the 'open for access' line or -
for some reason - Safari hasn't saved anything to it (or finished saving
to it) when the code first runs. Is the Safari download happening in the
same script?
NG
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.