Mail Attachments sichern

.emlx Dateien sind der Speicherort für Emails ab Mac OSX... ehm 10.5? Hier ein dirty-work-around zum automatischen Speichern von Anhängen in Apple Mail, da es direkt via AppleScript noch nicht möglich zu sein scheint siehe Update weiter unten (Automator zählt nicht ;-) ). Geht aber leider nur mit IMAP-Postfächern
Code zum markieren einmal anklicken

--© hubionmac.com 17.09.2009

--Stores attached pdfs (of an email received via IMAP) on your desktop

-- renames them by date received.... !!!MV overwrites existiting files!!!!

tell application "Mail"

set a to selection

end tell

repeat with s in a

tell application "Mail" to set current_date to date received of s

--convert applescript date to date string

set current_date to AppleScriptDateToString(current_date)

tell application "Mail"

--this works only on imap account, because there attachments are stored in a searate folder, not inline in .emlx-files

set attachments_path to do shell script "find ~/Library/Mail/ -name " & (id of s)

set current_attachments to do shell script "find " & quoted form of attachments_path & " -type f -iname \"*.pdf\" -exec mv {} ~/Desktop/" & current_date & ".pdf \\;"

end tell

get current_date

end repeat




on AppleScriptDateToString(a)

set b to current date

set monthnames to {}

repeat with i from 1 to 12

set month of b to i

set monthnames to monthnames & {(month of b) as text}

end repeat

set Y to (year of b)

set M to 0

repeat with t in monthnames

set M to M + 1

if t as text = (month of b) as text then

exit repeat

end if

end repeat

set M to Twodigits(M)

set D to Twodigits(day of b)

set hh to Twodigits(hours of b)

set mm to (minutes of b)

set ss to Twodigits(seconds of b)

--"2009-12-17 01:26:49"

--return Y & "-" & M & "-" & D & " " & hh & ":" & mm & ":" & ss as text

--"2009-12-17 01:28"

--return Y & "-" & M & "-" & D & " " & hh & ":" & mm as text

--"2009-12-17"

return Y & "-" & M & "-" & D as text

end AppleScriptDateToString

on Twodigits(a)

return (characters -2 through -1 of (("0" & a) as text)) as text

end Twodigits

UPDATE

Dieser Code ist deutlich besser, kommt mit bereits vergebenen Dateinamen klar und funktioniert auch mit jeder Art von Apple-Mail-Account =)
Code zum markieren einmal anklicken

(**

hubionmac.com 17.09.2009

save pdfs from seleceted email messages and save them in one folder

renames attachments by date received and from address like:

2009-12-09 from Steve Jobs <steve@apple.com>.pdf

2009-12-09 from Steve Jobs <steve@apple.com> 1.pdf

2009-12-09 from Steve Jobs <steve@apple.com> 2.pdf 


**)

set theAttachmentPath to (path to desktop) as text

tell application "Mail"

set a to selection

end tell

repeat with s in a

tell application "Mail"

set current_date to date received of s

set CurrentSender to sender of s

end tell

set current_date to AppleScriptDateToString(current_date)

tell application "Mail" to set Attached to mail attachments of s

repeat with ThisAttach in Attached

tell application "Mail" to set FileName to name of ThisAttach

if FileName ends with ".pdf" then

set FileName to current_date & " from " & CurrentSender & ".pdf" as text

set FileName to checkname_with_pdf_suffix(FileName, theAttachmentPath, false)

tell application "Mail" to save ThisAttach in theAttachmentPath & (FileName)

end if

end repeat

end repeat



on AppleScriptDateToString(a)

set b to a

set monthnames to {}

repeat with i from 1 to 12

set month of b to i

set monthnames to monthnames & {(month of b) as text}

end repeat

set Y to (year of b)

set M to 0

repeat with t in monthnames

set M to M + 1

if t as text = (month of b) as text then

exit repeat

end if

end repeat

set M to Twodigits(M)

set D to Twodigits(day of b)

set hh to Twodigits(hours of b)

set mm to (minutes of b)

set ss to Twodigits(seconds of b)

--"2009-12-17 01:26:49"

--return Y & "-" & M & "-" & D & " " & hh & ":" & mm & ":" & ss as text

--"2009-12-17 01:28"

--return Y & "-" & M & "-" & D & " " & hh & ":" & mm as text

--"2009-12-17"

return Y & "-" & M & "-" & D as text

end AppleScriptDateToString

on Twodigits(a)

return (characters -2 through -1 of (("0" & a) as text)) as text

end Twodigits



on checkname_with_pdf_suffix(n, D, looped)

tell application "Finder"

set thefiles to name of every item of (D as alias)

end tell

if thefiles contains n then

if looped = false then

set n to ((characters 1 through -5 of n) & " 1" & (characters -4 through -1 of n)) as text

checkname_with_pdf_suffix(n, D, true)

else

set tmp to (last word of ((characters 1 through -5 of n) as text) as integer)

set tmpcount to (count of characters of (tmp as text)) + 5

set tmp to tmp + 1

set n to ((characters 1 through (-1 * tmpcount) of n) & tmp & (characters -4 through -1 of n)) as text

checkname_with_pdf_suffix(n, D, true)

end if

else

return n

end if

end checkname_with_pdf_suffix

This entry was posted in Apple Mail and tagged , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CAPTCHA:


+ five = 10

Subscribe without commenting

  • Seite übersetzen:


    Paypal for Pizza:




  • Kategorien


  • Letzte Kommentare

    • Niklas: Vielen Vielen Dank! So klappt es!
    • hubi: Servus Niklas, ich habe mir den Quellcode noch einmal angesehen und habe nun unter 10.7.3 einen Weg gefunden...
    • Niklas: Klingt super das Script. Leider bekomm ich immer folgende Fehlermeldung: error “„Mail“ hat einen Fehler...
    • Jürgen: Hallo Hubi, beim Abfragen von Kennworten gibt es noch eine böse Falle: Das Format, in dem security antwortet,...
    • hubi: Am einfachsten Du öffnest im AppleScript-Editor mal das Funktionsverzeichnis (unter Ablage) von iTunes. Ein...