Automatically Save Attachments in

At the request from  :   Brian Jones

I wrote an Applescript for a Rule that will Automatically Save Attachments in .

 (* For Yosemite : please see Reported issues below *)


The script uses the mail senders email address to gives each sender their own attachments folder.

Each messages attachments from the sender is then placed in a time stamped folder. The time stamp derives from the date received of the message.

I have not put in any code to mark the message as read or processed. But you can do this if you want.


Applescript Editor

Open script in Applescript Editor


 1- Where to save the Script file

Unlike previous Os versions where you could place your Applescript any where in the file system.  In 10.8 you need to place Applescripts in:
~/Library/Application Scripts/
You can simply copy the above path, open a new Finder window.
Hit the keys Cmd + Shift G A sheet will slide down. Past the path in the text field and hit Go.
you will be taken to the folder. Place you Applescript file inside. Screen Shot 2013-03-29 at 12.57.57
The Script will now appear for your selection in the Mail Rules. Screen Shot 2013-03-29 at 13.04.08


2 -- Setting your sub folder path for the saved attachment directories and files.

If you wish to change the path of where your attachments folders go. You can make a simple change to the line of code :

set folderName to "Attachments".

For example I want my attachment folders to go into:


The folderName  line will look like this:

set folderName  to  "documents:mailstuff:mail_Attachments"

Notice the colons (:) they are used instead of the forward slashes (/) to mark directorie separation.

Make sure you do not put a colon at the beginning or at end of your path. They are not needed.

The path to the user home folder is set later on in the line:

set homePath to (path to home folder as text ) as text

So you only need to concern yourself with sub folders of the user home folder.

Another thing to note.

If you only have some of the directories in the folderName path or none at all. The script will create them. It will not over write any folders already existing but will add the missing intermediary ones.

Tested on : Mac Os 10.8.3 ,  Version 6.3 (1503)

Reported issues:

1, I have filed a bug report  (below) with Apple: Nov. 2014 this will most likely be  a duplicate as ALL theses types of Applescript will be affected and others have noticed it. Hopefully apple will fix this soon.

The Problem is not with the code here. so please do not post comments if you are using Yosemite and getting the error described below.**Update -- Apple have closed my Bug report on this as a duplicate. This means they are still looking at it..

Bug Report:

As of 10.9  and 10.10 ( Yosemite) you can no longer access's 'mail attachments' from Applescript.

This means you cannot save or count them.
You will 9 times out of 10 get resulting  error "error "Mail got an error: AppleEvent handler failed." number -10000"
This appears to happen for 90% of the emails that are in an inbox, individual or consolidated ones.
This bug is reproducible when using a "get selection" Applescripts
This bug is reproducible when Performing a "Run Applescript" action in the mail Rules.


2, Reported in   comment . :   Umlauts   in folder names may stop the script from completing.

The removal of  umlauts from the name solved the problem.

126 thoughts on “Automatically Save Attachments in

  1. Hi Mark,

    I have tried inputting the code into a rule in El Capitan but I am not having any joy. I see other users say that they have got it to work. Perhaps you or they could help me.

  2. Hello Mark, you very very great……. I wonder if it's possible with an applescript zip all emails that have in their body the same content.
    For example i have 8 email that have in the body this word "identify 76547".
    It's possible with applescript zip all 8 email?
    Thank for your interest

  3. How can you use this to save a pdf included in the body of an email to a folder on your Desktop?

  4. Hi Mark,

    Thanks for this script.

    It works well on 10.11.2 El Capitan.

    but, is It possible to save the body of the email in same place

    Thank you in advance!


  5. This is really great. Only question:

    I just want my attachments to be saved into an Attachments folder on my desktop, and only have one subfolder that is the name of the sender. Every time the sender sends something it will go into that particular subfolder folder.

    I do not want to have any timestamps or dates as further subfolders. Can you assist?

    Thank you in advance!

  6. I looks like the last update on this was 4 months ago. This script is exactly what I have been looking for but I see it doesn't work correctly. I have OS X 10.10.2 so maybe its still buggy. When I run the script all the folders and subfolders get created but there aren't any attachments in them. I was reading a couple other forums of people trying almost the same thing (auto download attachments) and a saw a couple mentions of it needing to be run through the "Downloads" folder because of the sandbox thing. If i knew anything about applescript I'd try that myself.

  7. Hi,

    Yes if you have set everything up correctly then this may happen because of the Bug in We can only wait for apple to fix this. This problem is universal for every script that looks at Mail attachments in the way until then.

  8. Hi!

    I made a rule in Mail as described and I saved the script in the specific folder. There just happens nothing. I get no error message. No folders are created.

    Kind regards


  9. Hi, Can you explain what you mean by doesn't work. If when you run the script you get an error??

    There is a bug in that is breaking script that look for attachments. So if anyone has linked to my code it will produce the same results. ( This is the Original code ) We are waiting for apple to fix the bug.

  10. Hi!

    I tried the script for several times, but it does not work. Has somebody got another link?



  11. Hi bocaboy, there appears to be a bug in Applescript or Mail which is stopping most attachments from being returned to the applescript. I am trying to pin it down so I can pass it in to apple as a bug if no one has already done so. At the moment there is no proper work around apart from maybe have a first action that moves the email first to a mailbox in 'on my mac'. I.e. Local. I will try and update here when i know more. Cheers

  12. Mark, has something changed with Yosemite and the new version of Mail? I've been successfully running your script to detach images from an account and save them, (thank you!) but with Yosemite I find the image isn't saved although the directory entries are, in fact, created. Are there any modifications that need to take place to re-enable the script?

  13. Thanks very much, Mark. I appreciate the prompt reply and guidance on how to implement my modification.

  14. Hi M.C,

    There are notes at the bottom of the post where I explain about chnaging the path to what you want. All you need in to do is find the relevant code in the script and change it. (read note 2)

    your path for dropbox would be something like set folderName to "Dropbox:mail_Attachments"

    The script is written to run from a Mail rule. Read note 1 to see how to set that up so it runs on all new messages.

  15. Mark,

    Thank for sharing this idea and nice piece of work, which I just came across after a Google search. I, too, am not AppleScript expert, and I hesitate to make changes to your script, especially since it involves the overly complicated structure (in my opinion) of Apple's The attachments can cause, as you know, an explosion in the size of one's Mail folder in the User Library. I was deleting images before deleting the actual email, but your Applescript idea prompted me to think it would be great to save the attachments that I might care about keeping, but have them moved to a folder in my Dropbox account instead.

    Would you mind sharing how you would edit the script so that, when its run, the attachments are moved to a Dropbox folder named "Mail Attachments"? And just to affirm my lack of knowledge on Applescripts, would this run automatically on any email that I open? Or do I run the script on an individual email that has an attachment that I want to save in Dropbox?

    Thanks very much for this generous public service to Mac users!

    All the best,

  16. Hi,
    You can use the unix command touch but in reality it only will do the modification date. Which can be change again at any time so in my opinion is not really a good choice for this.

    The way I would go about this is to use the setFile tool that comes with Apple's Xcode developer tools. It appears that in mavericks you can now just install the command line tools without installing xcode.

    In type: xcode-select --install

    This will give you a popup dialogue that gives you three options:
    command line tools

    Choose install.

    I have not done it this way myself but that should work ok.

    You can then change the time stamp code or add it as a new variable:
    set timeMod to ((m as integer) & "/" & my pad(d) & "/" & y & space & my pad(h) & ":" & my pad(min) & ":" & my pad(secs)) as string

    Then change the try block like this:

    save theAttachment in file (savePath)
    do shell script "/usr/bin/SetFile -d " & quoted form of timeMod & space & quoted form of (POSIX path of savePath)
    end try

    Hope that helps

  17. Thanks Mark for the quick reply.

    I meant to modify the actual file creation and/or modification date, not to add it to the file name.

    Is that possible?


  18. Hi Julian,

    The variable timestamp holds the date received of the mail message.

    So you can change the line:
    set savePath to attachmentsFolder & ":" & subFolder & ":" & timeStamp & ":" & originalName


    set savePath to attachmentsFolder & ":" & subFolder & ":" & timeStamp & ":" & timeStamp & "_" & originalName

    This will add the date at the beginning of each file.

  19. Hi Mark,

    Thanks for this very useful script.

    I have modified it slightly to save the attachments in monthly folders, I'm running on Mavericks and all is okay.

    However, I'm not an applescript expert, and I would like to have the files saved with the file creation/modification dates set to the actual email dates instead of the date/time the script was run.

    Is this possible, and if it is, can you help me out?

    Thanks again,


Hi, Please Leave a Reply