I have a script I use to make custom messages to a list of of people in an address group. When I upgraded to Tiger it quit working. I’ve been trying to get the group mailer in automator to approximate my broken script but I can’t get it to work either. Thanks for your help and ideas.
Here’s the script:
–Email.scpt written by David Johnson
(*
Script generates a mail merge to a contact list called “EList”
To use: create an new email in mail, you can leave the “to:” field blank, but as
the subject put “Daily Family Email”. Fill in the body with what you want to say
and then run the script. The script will generate on email for each person in the
Elist conact list
Note: this script won't copy fonts and coloring as the applescript to grab a message content only gets plain text
*)
–make sure address book is running
launch application “Address Book”
–create the date to use as the default subject line
set current_month to month of (current date)
set current_day to day of (current date)
set current_year to year of (current date)
set default_date to (current_month as string) & " " & (current_day as string) & ", " & (current_year as string)
–look in mail to find a window that contains the body of the email we want to send
set theBody to “undefined”
tell application “Mail”
activate
set mailWindows to every outgoing message
repeat with currentWindow in mailWindows
tell currentWindow
if subject is “Daily Family Email” then
set theBody to content of currentWindow
end if
end tell
end repeat
if theBody is equal to “undefined” then
if (count of mailWindows) is equal to 0 then
display dialog “In order to use this script you need to create a new message and put what you want to say in the body. If you have more than one compose window open then put the subject ‘Daily Family Email’ in the one you want to use. Do that first, then run this script” buttons {“Quit”} default button “Quit”
return
else
set theBody to content of item 1 of mailWindows
end if
end if
end tell
– Prompt for message subject
set theResult to display dialog “Subject of Email:” default answer default_date
set theSubject to text returned of theResult
– Use the default signature, or none if there isn’t any signatures available
tell application “Mail” to set everySignature to name of every signature
set theSignature to “”
if (count of everySignature) is greater than 0 then
tell application “Mail” to set theSignature to signature (item 1 of everySignature)
end if
tell application “Address Book”
–retrieve all of the people in the contact list
set groupName to “EList”
set the_group to every person in group groupName
--loop through all people in the group list
repeat with currentPerson in the_group
--retrieve information for contact
set contact_name to name of currentPerson
set contact_email to item 1 of every email of currentPerson
set email_value to (value of contact_email)
set namesList to related names of currentPerson
--make the defaults undefined
set contact_salutation to "Hi!"
set contact_signature to "In Him, Dwight and Beckie"
--retrieve the salutation and signature to use for the person
repeat with currentname in namesList
if label of currentname is "Salutation" then
set contact_salutation to (value of currentname)
end if
if label of currentname is "Signature" then
set contact_signature to (value of currentname)
end if
end repeat
tell application "Mail"
-- Properties can be specified in a record when creating the message or
-- afterwards by setting individual property values.
--add the salutation and signature on to the body
set bodyAppended to contact_salutation & return & return & theBody & return & return & contact_signature
--create the new message
set newMessage to make new outgoing message with properties {subject:theSubject, content:bodyAppended & return & return}
--futhur specify properties of the message
tell newMessage
set visible to true
make new to recipient at end of to recipients with properties {name:contact_name, address:email_value}
if (theSignature is not equal to "") then
set message signature to theSignature
end if
end tell
send newMessage
end tell
end repeat
end tell
Model: iMac
Browser: Safari 412.2
Operating System: Mac OS X (10.4)