Oddly, I got an error in AppleScript Editor. But it worked fine if I added the end of the 2nd line, " with write permission"
But it still would not work in FileMaker. It just won't go with the "write" command (as you said). One way to get past this is to use another app to run it, just as "Finder". A better add to use is "System Events", which is kind of made for such situations, as it's always available, and it doesn't show anything else.
set someText to the clipboard
tell app "System Events"
set myFile to open for access ((path to documents folder as text) & "foo.text") with write permission
write someText to myFile
close access myFile
This will "add to" above whatever text is in that file. However, this only works correctly if the file is empty to start with. As, without being told, it will just start writing, overwriting whatever is there. It seems there are two main options:
A. Clear the file first, then write the new text
B. Put the new text at the top, or add the bottom
I (kind of) know how to do each. But which (if any)?
Oh, a third alternative. Write a new file for each. Or is the "foo.txt" is just what you're showing us (for a shorter post)? That you are writing separate files for each?
Thanks. At least I know I'm not crazy as you seem to have the same issue. I'll give your idea a whirl. Another approach is to use AppleScript to talk to TextEdit to write the file. I've not quite figured that all out but it seems doable.