I use mailtags and mail act-on to substitute a special signature for people who are associated with a certain project, and need a quick way to add people who email me to the Contacts Group to which all outgoing messages are checked to see if their recipients are members of that group. The group is a smart group which includes everyone in the address book who has a certain piece of text in their note field.
The script will be run from a keystroke in Mail.
I can extract the email address of the sender from Mail but when I try and use that address to find a contact in Contacts and then edit the note to ensure they get made a member of the group, I get a problem - contacts throws an error saying:
Contacts got an error: Can’t make "john@doe.com" into type specifier.
It would seem that the format in which mail is outputting the address is text, but I have no idea how to refer to the email address in a format that means Contacts can use it…
tell application "Mail"
set themessages to selection
repeat with eachmessage in themessages
set theaddress to (extract address from sender of eachmessage)
tell application "Contacts" to set value of note of (first person whose value of email 1 is theaddress) to "my group"
end repeat
end tell