lazenca
Jan 15, 2009, 01:57 AM
Hi I am using AppleScript for the Mail app.
This is the workflow I wanted:
- Check any incoming messages with the subject that contains the word "SOA"
- Place them into the mailbox called SOA
- Save the attachment into my hard disk and in a folder of mine
This is the Mail rule I set in preference
http://i5.photobucket.com/albums/y177/bensonchan/Picture1-1.png
The AppleScript I used:
using terms from application "Mail"
on perform mail action with messages theMessages
tell application "Mail"
repeat with theMessage in theMessages
if name of theMessage's mailbox is "SOA" then
try
set numAttachments to number of theMessage's mail attachments
if numAttachments is 1 then
set theAttachment to first item of theMessage's mail attachments
set savePath to "Macintosh HD:Users:benson:Public:Drop Box:SOA:"
set attachmentFileName to savePath & theAttachment's name
tell application "Finder"
try
delete the attachmentFileName
end try
end tell
save theAttachment in attachmentFileName
if the mailbox "soa" exists then
move theMessage to the mailbox "SOA"
end if
end if
on error errMsg number errNumber
display dialog errMsg
end try
end if
end repeat
end tell
end perform mail action with messages
end using terms from
The problem is, whenever any email with the subject SOA is being received, it automatically goes into mailbox SOA but doesnt save the attachment into my hard disk.
I will then need to manually right click on the message(s) and choose "Apply Rule" for it to save the attachment file into my own folder.
Appreciate help. Thanks alot!:apple:
This is the workflow I wanted:
- Check any incoming messages with the subject that contains the word "SOA"
- Place them into the mailbox called SOA
- Save the attachment into my hard disk and in a folder of mine
This is the Mail rule I set in preference
http://i5.photobucket.com/albums/y177/bensonchan/Picture1-1.png
The AppleScript I used:
using terms from application "Mail"
on perform mail action with messages theMessages
tell application "Mail"
repeat with theMessage in theMessages
if name of theMessage's mailbox is "SOA" then
try
set numAttachments to number of theMessage's mail attachments
if numAttachments is 1 then
set theAttachment to first item of theMessage's mail attachments
set savePath to "Macintosh HD:Users:benson:Public:Drop Box:SOA:"
set attachmentFileName to savePath & theAttachment's name
tell application "Finder"
try
delete the attachmentFileName
end try
end tell
save theAttachment in attachmentFileName
if the mailbox "soa" exists then
move theMessage to the mailbox "SOA"
end if
end if
on error errMsg number errNumber
display dialog errMsg
end try
end if
end repeat
end tell
end perform mail action with messages
end using terms from
The problem is, whenever any email with the subject SOA is being received, it automatically goes into mailbox SOA but doesnt save the attachment into my hard disk.
I will then need to manually right click on the message(s) and choose "Apply Rule" for it to save the attachment file into my own folder.
Appreciate help. Thanks alot!:apple:
