textedit save as unicode 8

I am a complete newbie to write scripts in applescript, but i need one.
so anyone can help me please :slight_smile:

I’ve an exportfile from filemaker that should import into firstclass. the problem ar the different textformats.
I am opening the export-file in word and saving as text file (i’ve got it with applescript).
but now i have to reopen it with simpletext and save as unicode 8 file. and that is not working.

the command save as is not realy working :o

so please help me please…

Hi, surb. Welcome to MacScripter.

You probably don’t need to use TextEdit for the conversion to UTF-8. AppleScript’s own File Read/Write commands should be OK:

-- After the code to export from Word:

set fRef to (open for access file "path:to:text:file" with write permission) -- Substitute the path to your text file.
try
	set plainText to (read fRef as string)
	set eof fRef to 0
	write «data rdatEFBBBF» to fRef -- UTF-8 BOM. (May not be necessary. Depends on the software for which the file's being written.)
	write plainText to fRef as «class utf8»
end try
close access fRef

I don’t use FileMaker or Word, so I don’t know if its possible to export UTF-8 from them directly.

thanks nigel!

the script works like a charme with script editor :-)))
but the script is embedded into filemaker and filemaker does not understand fRef:mad:

There are a few AppleScript commands that FileMaker does not like in its “tell block”. One of them is “write”, likely “open for access.” Not sure about “eof” or “read”. One way to handle this I think is to put that all into a subscript, then call it, passing the data in a parameter. FileMaker is happy with that.

A related fact is that everything at the top level of an AppleScript inside a FileMaker Perform AppleScript step IS implicitly in a FileMaker tell block. You do not really need or want the 2 lines:

tell application “FileMaker Pro”
bunch of commands
end

But they are needed within Script Editor (AppleScript Editor now), which is where you write the script (I do anyway). The best thing to do is just comment them out, after pasting into FileMaker; so you’ve still got them if you need to take out to edit later, just remove the comments.

So, in FileMaker it would look more like this (pseudo code):

–tell application “FileMaker Pro”
bunch of commands
my write_file(aPath)
–end

on write_file(aPath)
all your write file stuff
end write_file