Locked files, logging to a file

Howdy,
Two quickie questions from a newbie.
First of all, how do I overwrite locked files from within a script (or, alternately, how do I unlock a file so that I can delete it?)
Secondly, I have been using the “log ()” function extensively. Is there any way that I can have the script log to a text file?
Thanks a million! Eric Richard

You use the Finder to unlock a file (“locked” is a file property):

tell application "Finder" to set locked of alias "Mac HD:someFile" to false

In the Standard Additions are a group of commands used to create, write, and read text files:

When I need to write a log file I usually write a handler to which I send text strings and which writes them to a text file. Although it takes a little longer to process, it is best to open, write, and close with each entry. If your script fails this avoids leaving you with an open text file.