from TextEdit to FileMaker with formatting

How do I transfer text from a TextEdit document to a FileMaker field without losing the formatting? The following script moves the text, but I lose linefeeds, color, and font. I’m even OK with losing color and font if I can at least retain linefeeds.


-- request the directory containing the Word document files
set inputFolder to quoted form of POSIX path of (choose folder with prompt "Select folder which contains the copy word file(s)" without invisibles)

-- get the list of Word document files
set theFiles to paragraphs of (do shell script "find " & inputFolder & " | grep .doc")
runScan(theFiles)

-- get the text of each file and put it in a new FileMaker record
on runScan(theItems)
	repeat with anItem in theItems
		tell application "TextEdit"
			set docFile to (open POSIX file (contents of anItem) as alias)
			set docCopy to text of document 1
			close document 1
		end tell
		tell application "FileMaker Pro Advanced"
			tell table "copy_archive"
				create record
				tell last record
					set contents of cell "server_file_path" to POSIX path of anItem
					set contents of cell "text" to docCopy
				end tell
			end tell
		end tell
	end repeat
end runScan

Model: MacBook Pro
AppleScript: 1.10.7
Browser: Firefox 2.0.0.3
Operating System: Mac OS X (10.4)

I’m not able to pass formatting either. But I can get the line breaks. I think the basic problem is the FileMaker text fields’s internal return is the old Mac style return, whereas many newer apps using the Unix line feed (Mail does also). AppleScript just passes it straight, so the Unix returns don’t work in the FileMaker field. If you translate them to Mac returns they do:


tell application "TextEdit"
	set theText to text of document 1
	set theText to my switch(ASCII character 10, ASCII character 13, theText)
end tell

tell application "FileMaker Pro Advanced"
	set cell "FileText" of current record to theText
end tell

on switch(char1, char2, str)
	-- switch char1 to char2 in str
	set od to AppleScript's text item delimiters
	set AppleScript's text item delimiters to char1
	set temp to text items of str
	set AppleScript's text item delimiters to char2
	if (class of str is string) then
		set temp to temp as string
	else if (class of str is Unicode text) then
		set temp to temp as Unicode text
	end if
	set AppleScript's text item delimiters to od
	return temp
end switch

this is a fairly consistent request however, it the only thing I have found that comes close is to use copy and paste. But that does seem to work 100% of the time,

mm

Thanks Fenton! Your solution carried over the returns perfectly, and solved my problem.