Mail-Regel-Skript: Attachments sichern

Hier ein simples Skript, welches Anhänge von Emails in einem vordefinierten Ordner sichert. Das kann man an eine Mail-Regel hängen.
Code zum markieren einmal anklicken Code im Skript-Editor öffnen

-- hubionmac.com 2010-01

-- script to be added to a Apple Mail rule

--saves attachmens of new mails into a folder

on perform_mail_action(info)

tell application "Mail"

tell application "Finder" to set mypath to (folder "Mail Attachments Saved" of desktop) as text

set theMessages to |SelectedMessages| of info

repeat with thisMessage in theMessages

try

repeat with a in (every mail attachment of thisMessage)

set current_a_name to name of a

set current_a_name to my checkname_with_pdf_suffix(current_a_name, mypath as alias, false)

save a in mypath & current_a_name

end repeat

on error msg

do shell script "echo " & quoted form of msg & " | cat>>~/Desktop/MailscriptErrorLog.txt"

end try

end repeat

end tell

end perform_mail_action



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

my 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

my 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.

7 Comments

  1. Posted July 4, 2010 at 5:37 pm | Permalink

    das script ist ja fantastisch :)
    1 fragen habe ich allerdings:
    ich möchte gerne mehrere mails > 300 gleichzeitig so abarbeiten. was müsste ich im script ändern?
    grüsse aus der schweiz,
    abi

  2. hubi
    Posted July 4, 2010 at 7:49 pm | Permalink

    Eigentlich musst Du nur etwas weg nehmen.
    on perform_mail_action(info) und end perform_mail_action(info)
    Das ist alles. Dann einfach die betreffenden Emails auswählen und das Skript anfeuern.

  3. vati
    Posted August 8, 2010 at 9:52 am | Permalink

    Hallo zusammen,

    wie kann ich das Script nur für bestimmte Anhänge verwenden?
    Also Anhänge, mit bestimmten Namen oder Mails mit bestimmtem Betreff.

    Danke & Viele Grüße
    der Vati

  4. Hubi
    Posted August 9, 2010 at 4:27 pm | Permalink

    Schau' doch mal in den Regeln in Mail nach.. dort kannst Du den Betreff und den Namen des Attachments mit als Bedingung angeben.

  5. vati
    Posted August 9, 2010 at 10:51 pm | Permalink

    Hallo Hubi,

    ich hab schon alles voreingestellt. Ich kann die Mail auch gut über Regeln selektieren. Nun möchte ich, dass das script den Anhang der selektierten Mail in einem bestimmten Pfad speichert und falls die Datei dort schon existiert, soll er diese mit der neueren ersetzen.
    Hier fehlt mir aber leider das Know-how. Ich kenne mich nur etwas mit VBA aus.

    Danke & Viele Grüße
    der Vati

  6. Hubi
    Posted September 2, 2010 at 8:22 pm | Permalink

    Schau' Dir doch mal an, wie die Variable mypath gesetzt wird und lasse mal die Zeile vor dem sichern der Datei (save a in mypath.... ) mal weg, ich denke das sollte es sein....

  7. jannis
    Posted September 24, 2010 at 6:59 pm | Permalink

    Sorry aber ich bin echt neu in sowas. check nicht wo ich den pfad setze wo der anhang hingespeichert werden soll...

One Trackback

  1. [...] eine leicht erweiterte Version diese Skriptes.... Code zum markieren einmal anklicken Code im Skript-Editor [...]

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:


8 × = thirty two

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...