Filemaker,, and Applescript

I’m trying to figure out a way to do the following:

  1. In Apple’s, select part of the body of an email message.
  2. Launch an AppleScript to copy the selection to the clipboard, then grab the email address of the sender, then perform a find based on the sender’s email address in a Filemaker 7 database.
  3. Paste the contents of the clipboard into a field in the database.

The last part is easy: once you have the data in the clipboard, you just run a script that will perform the find, then paste the data into the field. The hard part is finding how to pass the email address into the correct field while in Find mode. Any help is much appreciated.


If the second part is easy, I take it you know how to script filemaker? What kinds of problems are you running into when you try to script mail?

What I was originally trying to do was initiate the find using AppleScript. I now think a better way to do it is to move all the data to global fields, then start the Filemaker script to perform the find (using the Set Field script step). After the find is performed, the Filemaker script will put the contents of the email message into a new, related record in the database. On the AppleScript end, here’s what I’ve got:

tell application "Mail"
	set the_selection to (get selection)
	repeat with this_message in the_selection
		tell this_message
			set sender to get sender
			set subject to get subject
			set body to get content
			tell application "FileMaker Pro"
				tell database "Testdb"
					set cell "g_Email_Sender" of last record of table "FMTableTest" to sender
					set cell "g_Email_Subject" of last record of table "FMTableTest" to subject
					set cell "g_Email_Body" of last record of table "FMTableTest" to body
					do script "Find Email Sender"
				end tell
			end tell
		end tell
	end repeat
end tell

It works, but there’s another problem. Passing the body of the email message to Filemaker in this way removes all formatting (including returns), so it’s very hard to read, and the whole message (sometimes with multiple levels of quotes) gets moved to the database. What would be better is if the user could select the block of text he want to put in the database, and only that, would move to Filemaker. This would also preserve the relevant formatting. A really easy way to do it would be to copy the block of text to the clipboard, then use Paste in the Filemaker script, but I don’t know how to copy a selection using AppleScript. It can’t be hard, but I’m having trouble figuring it out. Any tips?