How do I save a file as RTF or Word 97 doc?

Hi there! I’ll be the first to admit that I don’t know what I’m doing. That said, I’m trying to get an already-formatted text field in FileMaker Pro 10 saved as an RTF or Word 97 doc (which seems to keep the formatting). The text field has font, font size and style attributes already applied. I can bring the data in from the clipboard if that helps any. I’m trying to use TextEdit as the vehicle but I’ll take any suggestions.

All of the following works as far as creating folders and saving the file, but the file is unreadable, so I don’t know what I’m doing wrong. Will saving a file as a .doc actually keep the rich text formatting or is there some sort of file format that needs to be used when writing the file? Here’s what I have:

tell application "FileMaker Pro"
    set year_foldername to cell "IssueYear" of current record
    set new_foldername to cell "IssueMMDDYY" of current record
    set Events to cell "All" of current record
end tell

set arcfolder to "Volumes:Archives:"
tell application "Finder"
    do shell script "/bin/mkdir -p " & quoted form of (POSIX path of arcfolder & "Coming Events/" &year_foldername & "/" & new_foldername)
end tell

set the_file to "Archives:Coming Events:"&year_foldername&":"&new_foldername&":"&new_foldername&".doc" 

tell application "System Events" to tell process "TextEdit" to set visible to false
tell application "TextEdit"
activate
open for access file the_file with write permission
write Events to file the_file  
close access file the_file
end tell

Thanks for any help!

Have you tried a simple save as? From the Textedit dictionary:

save‚v : Save an object.
save reference : the object for the command
[as Unicode text] : The file type in which to save the data.
[in alias] : The file in which to save the object.

something like

tell application "TextEdit" to save active document as RTF in the_File

That ‘tell TextEdit’ block is (part of) the problem. Those commands are not TextEdit’s, they are from the Standard Additions osax, so you’re talking to AppleScript, not TextEdit (it is considered good practice to not use osax commands within a tell block).

AppleScript knows nothing about .doc or .rtf (*) file structures. Those r/w commands can deal with plain text only.
You could try copying that text field to the clipboard, and then tell TextEdit to open a rtf document, and paste the clipboard. Try it by hand first, to see whether it would work.

I suspect this creates a pointer to the cell, not its value.
In that case this would be better (but check the wording in FileMaker’s dict):

(*) Although you can trick it into creating such a file. Formatting of content would not be preserved, I think.

Hello sharkwood,

What you’re trying to do can be done all within FileMaker.
The trick is to get the CSS of your formatted text field and export the result in an html file. After this you can easely convert html to doc, docx or rtf with the `textutil’ command line.

All you have to do is to add to your FMP file a new Text field “temp_g” and set it’s storage to “Global” (no need to be displayed on the layout).

Thank you both for your input, but I’m still not sure how to write the TextEdit portion of this.

Relish - your way seems simple but it gave me an error in code, undoubtedly because I don’t know how to get the info into the file before writing it.

Alastor - I don’t know “osax commands” from Oreos! I can get the formatted data to the Clipboard instead of pulling it from FileMaker. Manually, I can paste the Clipboard into a TexEdit document and save it, which is what I want to accomplish. I just don’t know how to script these steps. I’m sure it’s simple, but I have VERY little knowledge of scripting.

Starting with the info I want to save already formatted and on the Clipboard, please, if you both could just tell me verbatim what these few steps are starting with the “Tell TextEdit” statement to the “end tell” I would be so appreciative. I’ve spent days trying to figure this stuff out, and I’m not getting much closer to a solution.

Thanks again for your help!

Clemhoff, I just noticed your post after my last plea. I will try what you suggest. The Applescript I’m trying to write is embedded in FileMaker, so if I can accomplish my task within FileMaker, even better (I think).

Even simpler … (the global field “temp_g” is still required)

Clemhof, thanks for the short version, although there are two small problems:

  1. the field that has the formatted text is called “All” so the
    Set variable [$_pathToDOCFile_fmp; Value:Substitute ( $_pathToFolder_pos ; “/Volumes” ; “file:” ) & “/” & TO::All & “.doc”] isn’t quite right, but I’m not worried about that part.

  2. What is the “Quote” part of this line mean?
    Set variable [$_cmd; Value:"do shell script "mkdir -p" & space & quoted form of " & Quote ( $_pathToFolder_pos )]

I ran it without that word (as it’s unacceptable) and what I get is the HTML (?) code, literally, not the interpretation of that code.

Ideas?

Ooops! Sorry for that. That’s the “TO::IssueMMDDYY” that should be put here. … my bad …

According to Filemaker’s on-line help, the function Quote returns the text form of text enclosed in quotation marks.
Therefore it produces the following result for the local variable $ _cmd
do shell script “mkdir -p” & space & quoted form of “/Volumes/Archives/Coming Events/2010/Issue092310”
Without the quotes, FileMaker will generate an error at compile time of the AppleScript, but you can’t see it because FMP’s error handling is enabled. (Set error capture [On])