Skip to content

Instantly share code, notes, and snippets.

@henryroe
Created February 14, 2015 12:03
Show Gist options
  • Select an option

  • Save henryroe/085cead4751d19c2a5ad to your computer and use it in GitHub Desktop.

Select an option

Save henryroe/085cead4751d19c2a5ad to your computer and use it in GitHub Desktop.

Revisions

  1. henryroe created this gist Feb 14, 2015.
    15 changes: 15 additions & 0 deletions prepend_and_save.scpt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    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