I cobbled together the Apple Mail script below from various sources. I would like to attach this script to a rule and have it activate for specific incoming messages seined in my rule. I have the following problem; the script will run if I select a message and manually apply the rule but will not apply automatically to an incoming message.
I am new to applescript and am sure the syntax is off slightly, I was wondering if someone on this forum could give it a once over and comment.
The script, will save the attachment of a message to a folder, then create a new email and send to a specific person defined in the script with the original senders name in the subject line, original subject of the original email and the body of the original email but not the attachment.
Any help would be appreciated.
Thanks,
Ray
using terms from application “Mail” -----parts of bij mail rule aanzetten
on perform mail action with messages theMessages for rule theRule -----parts of bij mail rule aanzetten
tell application "Mail"
-- set theOutputFolder to (here's where you tell it the main folder to save in)
tell application "Finder"
set theOutputFolder to folder "Macintosh HD 2:Users:foo:Documents:Attachments"
end tell
-- Select the email account to apply the script
set theMessage to message 1 of mailbox "Inbox" of account "RTEST"
-- Set all object selections
set theSelection to selection
set theSelectedMessage to item 1 of theSelection
set theSelectedMessageSender to sender of theSelectedMessage
set theSelectedMessageSenderName to extract name from sender of theSelectedMessage
set theSelectedMessageSenderAddress to extract address from sender of theSelectedMessage
set theSelectedMessageSubject to subject of theSelectedMessage
set theSelectedMessageContent to content of theSelectedMessage
set ourText to " *** "
set theMessage to make new outgoing message with properties {visible:true, subject:"You've Got Pictures from *** " & theSelectedMessageSenderAddress & ourText & theSelectedMessageSubject, content:theSelectedMessageContent, reply to:"me@foo.com"}
-- Specify the recipients of the email
tell theMessage
make new to recipient at end of to recipients with properties {address:"me@foo.com"}
send
repeat with theMessage in theMessages
--does the message have attachments? if not, then skip it
if (every mail attachment of theMessage) ≠{} then
--save the attachment to the subfolder
set theAttachments to (every mail attachment of theMessage)
repeat with theAttachment in theAttachments
set thePath to (theOutputFolder as string) & (name of theAttachment)
--if same named file already exists in subfolder, skip it
if not (exists (alias thePath of application "Finder")) then
save theAttachment in thePath
end if
end repeat
set read status of theMessage to true
end if
end repeat
end tell
end tell
end perform mail action with messages
end using terms from
Model: 10.6
Browser: Safari 534.57.2
Operating System: Mac OS X (10.6)