Automatically saving email attachments to folder

Discussion in 'OS X Yosemite (10.10)' started by jpl1978, Aug 19, 2015.

  1. jpl1978 macrumors newbie

    Joined:
    Aug 19, 2015
    #1
    Hi there.

    I'm completely new to Mac's and therefore applescript. I've been looking for a way to automatically save attachments from emails into a specified folder. I understand there are 2 elements to the process - (1) creating an applescript, (2) creating the rule in Mail. I'm fine with the second point, but I'm struggling with the script...I've pasted what I've been trying to use below.

    I enter the script. Select the Compile option. Then save into specified folder for Mail rules. I set the rule up, but nothing is getting saved.

    Help! I have about 50 monthly reports that come through on email and this would make the job so much more efficient!


    using terms from application "Mail"

    on perform mail action with messagestheMessages

    set attachmentsFolder to "Volumes:<name of volume:<name of folder>:" as rich text

    tell application "Mail"

    set selectedMessages to theMessages

    try

    repeat with theMessage in selectedMessages

    repeat with theAttachment in theMessage'smail attachments

    set originalName to name of theAttachment

    set savePath to attachmentsFolder & originalName

    savetheAttachmentinfilesavePath

    end repeat

    end repeat

    end try

    end tell

    end perform mail action with messages

    end using terms from
     
  2. 0d085d macrumors regular

    Joined:
    Apr 23, 2015
    #2
    I think your problem lies in the save line, which should read:

    Code:
    save theAttachment in file (savePath)
    
    There are also a fair few missing spaces in the script you've copied in, but I assume they're just formatting errors. Just in case, here's the whole script as it works for me:

    Code:
    using terms from application "Mail"
        on perform mail action with messages theMessages for rule theRule
            set attachmentsFolder to "Volumes:<name of volume>:<name of folder>:" as rich text
            tell application "Mail"
                set selectedMessages to theMessages
                try
                    repeat with theMessage in selectedMessages
                        repeat with theAttachment in theMessage's mail attachments
                            set originalName to name of theAttachment
                            set savePath to attachmentsFolder & originalName
                            save theAttachment in file (savePath)
                        end repeat
                    end repeat
                end try
            end tell
        end perform mail action with messages
    end using terms from
     
  3. Michael_by macrumors newbie

    Joined:
    Mar 27, 2016
    Location:
    Maising
    #3
    thank you 0d085d!
    Had a similar problem, your post helped me very much.

     

Share This Page