Newbie needs script help - Mail to Filemaker

Okay, my apologies upfront I’m probably the worst kind of newbie. I’ve cobbled together a frankenstein of a script without completely understanding what I’m doing but so far it’s working.

Here’s the goal: Ability to copy the body of multiple emails from Mail.app and paste that into new records in a filemaker database.

So far I’m able to get it to work with a single email and only if the Filemaker database is already open.

I need help making it work on multiple messages and ideally a script step to open the database (and filemaker) if it’s not already open.

Any help/tips would be greatly appreciated!

Anthony

Here’s the script so far:

on perform_mail_action(info)
set allMessages to |SelectedMessages| of info
my generateItems(allMessages)
end perform_mail_action

on run
tell application “Mail”
set allMessages to selected messages of message viewer 1
my generateItems(allMessages)
end tell
end run

on generateItems(allMessages)
tell application “Mail”
set curMessage to item 1 of allMessages

	set curContent to content of curMessage
	tell application "FileMaker Pro Advanced"
		set newrec to create new record of table "Email Parser" of database "Email Parser"
		set cell "Email Text" of last record of the table "Email Parser" to curContent as styled text
		
	end tell
	
end tell

end generateItems

Great job…

Instead of just processing message 1, use a looping structure…l

like this…

repeat with {loop variable} in {list}
code…
end [repeat]

so…

repeat with curMessage in allMessages
set curContent to content of curMessage
tell application “FileMaker Pro Advanced”
set newrec to create new record of table “Email Parser” of database “Email Parser”
set cell “Email Text” of last record of the table “Email Parser” to curContent as styled text

    end tell

end [repeat]