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

MiniMoke

macrumors regular
Original poster
Nov 12, 2009
107
75
Black River, Mauritius
I know, this has probably been discussed a lot, but up to now I have not been able to find an easy solution for extracting mail attachments from Mail (latest version on Mountain Lion) and save them to a specific folder (In this case the Dropbox/Attachments folder in my home directory).

I tried Automator which can extract the attachments but can't, link to mail rules. Mail rules of course can't extract attachments and I even tried Applescript to accomplish this or to make the Automator workflow run but it didn't work.

What exactly am I trying to do: I want to extract mail attachments from newly arrived mails with a certain subject (!Dropbox!) and save them to my attachments folder within the Dropbox folder. This should happen automatically as soon as new mail arrives.

Is anyone, with a bit of patience and pedagogic skills, able to guide me step by step through this? Of course I'm totally new to Applescript though I have some little experience with mail rules and even Automator.

Thanks!!
 
Last edited:
Thanks a lot, but I tried the script (only adapted the location to my "Dropbox:Attachmentts"), folder but nothing happens when I send a mail with attachment.....

No Idea where my error lies but I probably got something wrong... or is this why SendToDropbox is not working for me?? Anyone had experiences with this?

Here's the script I pasted in AppleScript editor:



on perform_mail_action(ruleData)

-- The folder to save the attachments in (must already exist)
set attachmentsFolder to ((path to home folder as text) & "Dropbox:Attachments") as text

-- Save in a sub-folder based on the name of the rule in Mail
set subFolder to name of |Rule| of ruleData as text
tell application "Finder"
if not (exists folder subFolder of folder attachmentsFolder) then
make new folder at attachmentsFolder with properties {name:subFolder}
end if
end tell

-- Get incoming messages that match the rule
tell application "Mail"
set selectedMessages to |SelectedMessages| of ruleData
repeat with theMessage in selectedMessages

-- Get the date the message was sent
set {year:y, month:m, day:d, hours:h, minutes:min} to theMessage's date sent
set timeStamp to ("" & y & "-" & my pad(m as integer) & "-" & my pad(d) & "-" & my pad(h) & "-" & my pad(min))

-- Save the attachment
repeat with theAttachment in theMessage's mail attachments
set originalName to name of theAttachment
set savePath to attachmentsFolder & ":" & subFolder & ":" & timeStamp & " " & originalName
try
save theAttachment in savePath
end try
end repeat
end repeat
end tell

end perform_mail_action

-- Adds leading zeros to date components
on pad(n)
return text -2 thru -1 of ("00" & n)
end pad
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.