At the request from : Brian Jones
I wrote an Applescript for a Mail.app Rule that will Automatically Save Attachments in Mail.app .
(* For Yosemite : please see Reported issues below *)
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.
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 Mail.app Applescripts in:
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.
The Script will now appear for your selection in the Mail Rules.
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 , Mail.app Version 6.3 (1503)
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..
As of 10.9 and 10.10 ( Yosemite) you can no longer access Mail.app'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.app mail Rules.
The removal of umlauts from the name solved the problem.