Re: scripting a task in mail
Re: scripting a task in mail
- Subject: Re: scripting a task in mail
- From: David Gregg via AppleScript-Users <email@hidden>
- Date: Wed, 15 Jan 2020 10:45:56 -0800
Rowland,
This is a solution to your request that provides some added flexibility:
- a forwarded version of 1 or multiple selected email messages. This will
include the Fwd in the subject line and the forwarded quote level for the
content;
- multiple to recipients if needed. Just add other emails to the AppleScript
list toRecipientsList;
- if there isn't a common email address for the Neighbourhood Watch this will
pick up the email of the individuals within that group in Contacts. The label
for the bcc recipients needs to be common, e.g. "work" or "home" or a custom
one you create;
- you also have a choice of immediately sending them or leaving them open for
inspection. This option is changed by modifying the value of the
sendImmediately variable (false for inspection, or true for immediately
sending).
Regards
David Gregg
on run {}
set workEmails to my getContactsEmailAddress("Neighbourhood Watch",
"work")
set sendImmediately to true
set toRecipientsList to {"email@hidden"}
set bccRecipientsList to workEmails
set subjectPrefix to "[neighbourhood watch] "
my forwardSelectedMail(sendImmediately, toRecipientsList,
bccRecipientsList, subjectPrefix)
end run
on getContactsEmailAddress(groupName, emailLabel)
tell application "Contacts"
set groupContacts to group groupName
set labelledEmails to {}
repeat with i from 1 to count of people of groupContacts
set groupContact to person i of groupContacts
set contactEmailList to (value of emails of
groupContact whose label = emailLabel)
set contactEmail to first item of contactEmailList
set labelledEmails to labelledEmails & contactEmail
end repeat
end tell
return labelledEmails
end getContactsEmailAddress
on forwardSelectedMail(sendImmediately, toRecipientsList, bccRecipientsList,
subjectPrefix)
tell application "Mail"
activate
set currentSelectedMessages to selected messages of message
viewer 1
repeat with currentSelectedMessage in currentSelectedMessages
set forwardedMessage to forward currentSelectedMessage
tell forwardedMessage
repeat with toRecipient in toRecipientsList
make new to recipient at end of to
recipients with properties {address:toRecipient}
end repeat -- toRecipient
if bccRecipientsList is not equal to {} then
repeat with bccRecipient in
bccRecipientsList
make new bcc recipient at end
of bcc recipients with properties {address:bccRecipient}
end repeat -- bccRecipient
end if
set subject to subjectPrefix & subject
if sendImmediately then send
end tell -- forwardedMessage
end repeat -- currentSelectedMessage
end tell
end forwardSelectedMail
> On Jan 15, 2020, at 6:49 AM, Rowland Carson via AppleScript-Users
> <email@hidden> wrote:
>
> I’ve made some simple scripts for BBEdit and GraphicConverter (mostly by
> recording actions and editing the result) but not for any other applications.
> I have a task in Apple Mail that comes up frequently; I forward messages from
> the local police to all those in the local Neighbourhood Watch group.
>
> What I’d like to be able to do in AppleScript is to forward the
> currently-selected message to my own address, and BCC it to the Contacts
> group Neighbourhood Watch. Before sending, I want to insert the text
> “[neighbourhood watch] ” at the beginning of the message subject line.
>
> Can anyone offer suggestions about how to construct such a script?
>
> And, yes, I know I could probably achieve a similar result by setting up a
> Google Group - but not all of the recipients would be happy with that
> approach.
>
> in friendship
>
> Rowland
>
> | Rowland Carson ... that's Rowland with a 'w' ...
> | <email@hidden> http://www.rowlandcarson.org.uk
> | Skype, Twitter: rowland_carson Facebook: Rowland Carson
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> AppleScript-Users mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> Archives: http://lists.apple.com/archives/applescript-users
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden