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

jpl1978

macrumors newbie
Original poster
Aug 19, 2015
1
0
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
 

0d085d

macrumors regular
Apr 23, 2015
154
12
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
 
  • Like
Reactions: Michael_by

Michael_by

macrumors newbie
Mar 27, 2016
1
0
Maising
thank you 0d085d!
Had a similar problem, your post helped me very much.

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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.