Automatically Save Attachments in

At the request from  :   Brian Jones

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


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:

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

The removal of  umlauts from the name solved the problem.

104 thoughts on “Automatically Save Attachments in

  1. 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,


  2. 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.

  3. 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?


  4. 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

Hi, Please Leave a Reply