Did you try it in your script editor? It should have worked just fine.
The “write” command is a part of the Standard Additions scripting addition. All scripting addition commands are global in scope, they are available everywhere, in and out of tell blocks.
“Release?” What language are you coming to us from?
There are long standing problems with working with the read/write commands. Assuming you have the memory, (under OS X, you almost always have the memory), the best advice is to read an entire file into a variable, process it as a string, then write it back out again.
set myFile to alias "path:to:a:file"
-- The "open for access" command isn't really needed
-- when you're just reading:
--
set str to read myFile
... process the string str
try -- always be careful about a file opened with write permission
-- The "open for access" command IS needed for writing:
--
set openedFile to open for access myFile with write permission
-- If the processing of str made it smaller than it was,
-- the contents of myFile needs to be zeroed out:
--
set eof openedFile to 0
write str to openedFile
close access openedFile
on error e number n from f to t partial result p
try
close access openedFile -- try closing it
end try
-- re-throw the error:
--
error e number n from f to t partial result p
end try
The standard additions read/write commands are not used for reading/writing to documents opened in applications (i.e. they are not application commands). To write to an application, the app neads to be scriptable and contain commands that allow read/write.