Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

lazenca

macrumors newbie
Original poster
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
Picture1-1.png


The AppleScript I used:

Code:
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:
 
I think the problem is that you are moving the message before the attachment has been moved.
Try moving the attachment first, then moving the message second, you could probably rearrange the rule tasks to try this.

Regards Mark
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.