Hi Eros9. This is indeed very interesting, and potentially very helpful for a different thing I'm trying to do.
But I don't understand HOW you run the AppleScript in the context of a Text Factory. In the user guide the only mention I see of AS in relation to a TF is the "Run AppleScript Filter" option, which is documented as shown below. I'm kind of thrown off by the statement "This entry point should return the file’s contents as a Unicode string." Is this what you're using?
When you use the Run AppleScript Filter operation, your script should be written with an entry point named “ApplyTextTransform”. The input parameter to this entry point is a Unicode string containing the file’s contents. This entry point should return the file’s contents as a Unicode string (or something which can be directly coerced to one):
on ApplyTextTransform (fileData)
-- do something to fileData
return fileData -- or some reasonable facsimile thereof
end