OS X Mail - autonomous processing of email?
June 19, 2007 8:04 PM   Subscribe

Can Mac OS X Mail be configured to autonomously process email, and based on specific From: and Subject: lines, save the attachment(s) of that email into a specific folder?

I'm a dinosaur and prefer to ssh into my Unix based ISP to read my mail. So never having used OS X Mail before, I have no idea if it can do this. I want to be able to send email to a seldom used POP account and have Mail running on my Mac at home automatically check that account and save an attachment based on From/Subject lines. Possible?
posted by jaimev to Computers & Internet (6 answers total) 1 user marked this as a favorite
 
Mail can do filtering, but I just looked and don't immediately see a way to get it to save attachments automatically. Check under Preferences->Rules to see where you can create rules. You might have to use the rules to run an Applescript that will do the saving of the attachment. It looks like this script might do that, though I haven't used it.

If Mail.app cannot, you can always install and run procmail. This is hard to configure, and might be overkill.

I bet it can be done, and someone smarter than me with the Mac stuff will have an answer for you soon.
posted by procrastination at 8:16 PM on June 19, 2007


AppleScript is your friend. This MacTech magazine article is also you friend. I love AppleScript, so I'll pull the juicy bits out for you. Heck, I'll do all the work, too.
  1. Run the Script Editor (/Applications/AppleScript/Script Editor).
  2. Copy and paste the following code into the script window:
    on perform_mail_action(theData)
    	tell application "Mail"
    		set theSelectedMessages to |SelectedMessages| of theData
    		set theRule to |Rule| of theData
    		repeat with a from 1 to count theSelectedMessages
    			set theOutputFolder to ("Full:path:to:folder:") as string
    			set theMessages to selection
    			set theMessage to item 1 of theMessages
    			set theAttachments to every attachment of content of theMessage
    			repeat with a from 1 to length of theAttachments
    				set theAttachment to item a of theAttachments
    				try
    					set theAttachmentName to name of theAttachment
    					set theSavePath to theOutputFolder & theAttachmentName
    					save theAttachment in theSavePath
    				end try
    			end repeat
    		end repeat
    	end tell
    end perform_mail_action
    
  3. Replace the quoted part in parentheses with the correct, colon-separated path to your destination folder. Start with the name of your hard disk and and with a colon.
  4. Save the script in a convenient spot.
  5. Launch Mail.app and go to the Rules section of the Preferences.
  6. Add a new rule to match for the criteria you specify and make it perform an applescript action, choosing the previously created script. Click OK to save it.
  7. Close the Preferences and send yourself an email that matches the rule. If all goes well, the attachment will be saved to your desired folder.

posted by pmbuko at 10:39 PM on June 19, 2007


sorry about the extra lines in the code. looked fine on preview.

Step 3 should finish with "and end with a colon."
posted by pmbuko at 10:42 PM on June 19, 2007


One more thing: this script solution requires Mac OS X 10.4 (Tiger) or later.
posted by pmbuko at 10:44 PM on June 19, 2007


pmbuko - thanks for that Applescript. It's not quite working for me yet (attachment isn't being saved to my output folder, with no error indications), but you gave me enough info to get me pointed in the right direction.
posted by jaimev at 11:24 PM on June 19, 2007


Hmmm. This script works for me. For testing, make the rule match only one thing, such as the subject, and make it match exactly.
posted by pmbuko at 5:10 AM on June 20, 2007


« Older Dyscalculia Schools   |   Maybe this is all just glorified procrastination. Newer »
This thread is closed to new comments.