Applescript:

If you need this file into a text editor, we would recommend adding a little flag to the file, so the text editor recognizes this is a utf-8 encoded file:

Applescript:

set f to (open for access file x)set eof of f to 0 --> empty file contents if needed--> now write the flagwrite ((ASCII character 239) & (ASCII character 187) & (ASCII character 191)) to f --> not as Â«class utf8Â»--> now write the datawrite "foo"to f as Â«class utf8Â»
close access f