Skip to content

Instantly share code, notes, and snippets.

@henryroe
Created February 14, 2015 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henryroe/085cead4751d19c2a5ad to your computer and use it in GitHub Desktop.
Save henryroe/085cead4751d19c2a5ad to your computer and use it in GitHub Desktop.
Save mail attachments after pre-pending YYYY-MM-DD_
set outputPath to choose folder
tell application "Mail"
set curMessage to selection
set listAttachments to mail attachment of item 1 of curMessage
set curMessageDate to date received of item 1 of curMessage
set dateStr to (rich text -4 thru -1 of ("0000" & (year of curMessageDate))) & "-" & ¬
(rich text -2 thru -1 of ("00" & ((month of curMessageDate) as integer))) & "-" & ¬
(rich text -2 thru -1 of ("00" & (day of curMessageDate)))
repeat with a from 1 to length of listAttachments
set curAttachment to item a of listAttachments
set curSavePath to (outputPath as string) & (dateStr & "_" & (name of curAttachment))
save curAttachment in curSavePath
end repeat
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment