Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I have looked on stack exchange and other sites for a simple applescript. I have found more complex scripts that it's hard for me to understand (not knowing a lot about the applescript syntax). So, here's my dilemma:

I need to automatically download an attachment (i.e. named "blank expense report") to a specific folder (i.e. "Inbox"). That's it. I can setup the mail rule with parameters to find the attachment I'm looking for:

enter image description here

I just need a simple script to download the attachment.

I have looked at these but just got confused trying to alter them and actually messed up some non-essential files on my computer. So, I'll stop copying and pasting code and just ask for some help.

Questions I looked at before this.

Save attachments from Mail.app based on subject

Automatically Save Attachments in Mail.app in 10.8 Mountain Lion

share|improve this question

1 Answer 1

This is an edited version — quite possibly not the best one — of the script shown in this answer to the Automatically Save Attachments in Mail.app in 10.8 Mountain Lion thread, I've tested it and it works:

using terms from application "Mail"
    on perform mail action with messages theMessages for rule theRule
        tell application "Mail"
            repeat with eachMessage in theMessages
                repeat with theAttachment in eachMessage's mail attachments
                    set attachmentName to name of theAttachment
                    if attachmentName is "blank expense report" then
                        set savePath to "Macintosh HD:Users:yourUsername:Inbox:" & attachmentName
                        try
                            save theAttachment in file (savePath)
                        end try
                    end if
                end repeat
            end repeat
        end tell
    end perform mail action with messages
end using terms from

This script will save the attachment named "blank expense report" in a named "Inbox" at Machintosh HD:Users:yourUsername:Inbox. Be sure to change the value of savePath variable accordingly to your needs.

share|improve this answer
    
I'm not getting the rule to work. Nothing is downloading. I've changed the location to the correct one. I don't know how to troubleshoot this one. –  masterninja01 May 11 '13 at 19:03
    
Sorry I don't know what to say, it works here. I can suggest putting some display alert "something" in the code to get a hint about where the script stops working properly. –  Claudio d'Angelis May 12 '13 at 16:01
    
I tried what you said (thanks for the simple troubleshoot tip - i love it) and the script seemed to stop before the second to last line. Before end perform mail action with messages(aka the message didn't display after this section but did display before the line). –  masterninja01 May 29 '13 at 9:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.