file I/O with Standard Additions

I’ve been able to write to files with Standard Additions before without problems, but now I am having one that I can’t figure out. I have a file that is pretty much in HTML format(although saved as .txt), and then I want to prepend some more HTML to the beginning, and have it as an HTML file. This is what the script(which isn’t complete, but gives the general idea) looks like:

set doc to destHTMLFiles & fileName & ".txt"
	set myDoc to (open for access doc with write permission)
	set speech to read myDoc
	set temp to "<HTML>" & return & "<HEAD>" & return & "<TITLE>" & fileName & "</TITLE>" & return & "</HEAD>" & return & "<BODY>" & return & "<H2 align="center"><i>" & speechTitle of speechInfo & "</i></H2>"
	set HTMLDoc to destHTMLFiles & fileName & ".html"
	set myHTMLDoc to (open for access HTMLDoc with write permission)
	write temp & speech to myHTMLDoc
	close access doc
	close access HTMLDoc

However, I keep getting the error “File not open with write permission.”
Am I missing something here? Any help will be appreciated. Thank you

I restarted my computer, and now everything works fine. :? I was afraid I was going crazy.


That’s why you should use an error handler when using the standard additions read/write commands. You’re lucky that you could shut down your computer. Next time, open a new script and type:

set the_file to choose file – choose the file that you’re writing to
close access the_file

Your statement:

close access doc

doesn’t look right and may be causing the error.

Also, in this line:

close access HTMLDoc

it is faster to use the reference number:

close access myHTMLDoc


yeah, I realized after I posted that the close access should be changed. But I think I still got the same error after changing the statements you suggest. Things work great now, so…