I am trying to make a script that will send an e-mail to all the contacts within a group, but personalize and address each contact with Dear “name here”.
I have successfully completed the task, however, I have a new problem.
Problem:
As of now, the body of the message must be copied and pasted into the script.
However, I would like to have the body have special formatting (font, bold, italics, etc).
How can I best achieve this? Would copying and pasting from a draft email (using keystroke commands, etc) work? If so, how do I do this? I am fairly new to applescript.
Thanks!
--Prompt for attachment--
set theResult to display dialog "Would you like to attach some files to this message?" buttons {"Yes", "No"} default button 1
set wantsAttachment to button returned of theResult
if wantsAttachment is equal to "Yes" then
set theAttachment to choose file
end if
--Prompt for message subject--
set theResult to display dialog "What would you like the subject of the message to be?" default answer ""
set mySubject to text returned of theResult
--Body of Message [Please replace Message here with body. Add signature at the end of message body, if you so choose]--
set myMessage to "Message Here"
--Alert to select contacts--
display dialog "Please select the recipients in Address Book/Contacts"
--Under the hood, and activation, and send--
tell application "Contacts"
set theContacts to selection
repeat with contact in theContacts
my send_message(mySubject, "Dear " & name of contact & "," & return & return & myMessage, value of first email of contact, return)
end repeat
end tell
on send_message(theSubject, theBody, theAddress, theAttachment)
tell application "Mail"
set theNewMessage to make new outgoing message with properties {subject:theSubject, content:theBody & return & return, visible:true}
tell theNewMessage
set visibile to true
make new to recipient at end of to recipients with properties {address:theAddress}
make new attachment with properties {file name:theAttachment} at after the last word of the last paragraph
activate
end tell
end tell
end send_message
**Sidenote: if you run this, say yes to attach file. I didn’t put in the if/then commands for the attachment. I haven’t figured out where it goes. :rolleyes:
I added four instructions supposed to treat the case of you don’t want to attach a file.
--Prompt for attachment--
set theResult to display dialog "Would you like to attach some files to this message?" buttons {"Yes", "No"} default button 1
set wantsAttachment to button returned of theResult
if wantsAttachment is equal to "Yes" then
set theAttachment to choose file
else # ADDED
set theAttachment to "" # ADDED
end if
--Prompt for message subject--
set theResult to display dialog "What would you like the subject of the message to be?" default answer ""
set mySubject to text returned of theResult
--Body of Message [Please replace Message here with body. Add signature at the end of message body, if you so choose]--
set myMessage to "Message Here"
--Alert to select contacts--
display dialog "Please select the recipients in Address Book/Contacts"
--Under the hood, and activation, and send--
tell application "Contacts"
set theContacts to selection
repeat with contact in theContacts
my send_message(mySubject, "Dear " & name of contact & "," & return & return & myMessage, value of first email of contact, return)
end repeat
end tell
on send_message(theSubject, theBody, theAddress, theAttachment)
tell application "Mail"
set theNewMessage to make new outgoing message with properties {subject:theSubject, content:theBody & return & return, visible:true}
tell theNewMessage
set visibile to true
make new to recipient at end of to recipients with properties {address:theAddress}
if theAttachment is not "" then # ADDED
make new attachment with properties {file name:theAttachment} at after the last word of the last paragraph
end if # ADDED
activate
end tell
end tell
end send_message
Yvan KOENIG running El Capitan 10.11.1 in French (VALLAURIS, France) lundi 30 novembre 2015 21:04:39
I would like to run this script, but when I do I get:
error “Contacts got an error: Can’t get email 1 of person id "93A4E761-7010-47A4-AF67-4E86967E1718:ABPerson". Invalid index.” number -1719 from email 1 of person id “93A4E761-7010-47A4-AF67-4E86967E1718:ABPerson”