RTF als Email-Formatvorlage

23/03/2011
Sagen wir mal ich habe hier eine RTF-Datei die so aussieht:

Hey REPLACEME1,


how you are doing. Do you have time for REPLACEME2?


Yours REPLACEME3

Dann baut sich dieses Skript hier:

set mytemplate to choose file


set replace_list to {"my friend", "what ever", "hubionmac"}

set replace_markers to {}

repeat with i from 1 to count of replace_list

set replace_markers to replace_markers & {"REPLACEME" & i}

end repeat


tell application "TextEdit"

set mytextfile to open mytemplate

set mytext_parts to attribute run of mytextfile

set mylayout to properties of attribute run of mytextfile

close mytextfile

end tell

repeat with i from 1 to count of replace_list

repeat with k from 1 to count of mytext_parts

set item k of mytext_parts to my replace_chars(item k of mytext_parts as text, item i of replace_markers as text, item i of replace_list as text)

end repeat

end repeat


set mytext to mytext_parts as text


tell application "Mail"

activate

set myMessageText to make new outgoing message with properties {content:mytext, visible:true}

tell myMessageText

set globalcounter to 1

set pointer to 1

repeat with i from 1 to count of mytext_parts

set currentcount to count of every character of item i of mytext_parts

set font of characters globalcounter through (globalcounter + currentcount - 1) to (font of item i of mylayout)

set size of characters globalcounter through (globalcounter + currentcount - 1) to (size of item i of mylayout)

set color of characters globalcounter through (globalcounter + currentcount - 1) to (color of item i of mylayout)

set globalcounter to globalcounter + currentcount

end repeat

(**

--this does not work 100% since set word i does not wait for the command to finish

repeat with i from 1 to count of every word

set myword to word i

if myword is in replace_markers then

set word i to (item ((characters 14 through -1 of (myword as text)) as text as integer) of replace_list) as text

end if

end repeat**)

end tell

end tell


on replace_chars(this_text, search_string, replacement_string)

if this_text contains the search_string then

set od to AppleScript's text item delimiters

set AppleScript's text item delimiters to the search_string

set the item_list to every text item of this_text

set AppleScript's text item delimiters to the replacement_string

set this_text to the item_list as string

set AppleScript's text item delimiters to od

end if

return this_text

end replace_chars

.. aus dieser Vorlage eine neue Email, dessen Text entsprechend formatiert ist. Der Gag dabei ist die Geschwindigkeit und die Tatsache, dass das Ding ohne Zwischenablage und GUI-Skripting die Stil-Angaben der Vorlage übernimmt.
No Comments

Mail Applescript Bug

16/02/2011
Ist schon komisch in Apple Mail macht es teilweise einen gewaltigen Unterschied ob ein Skript so läuft oder in Folge eine Regel ausgeführt wird. Dabei scheint es hier aber ehr ein Fehler in der Implementierung zu sein... lasse ich dieses Skript von einer Regel ausführen:

on perform_mail_action(info)

tell application "Mail" to display dialog (count (every message of mailbox "INBOX" of account "1")) as text

end perform_mail_action

bekomme ich im Dialog stehst eine 1 ausgegeben und in der Konsole läuft folgender Fehler auf. 16.02.11 01:36:24 Mail[189] A key or value could not be handled while converting an Apple event record to an NSDictionary. Klicke ich direkt auf eine Email und wähle im Kontext-Menü "Regel Anwenden" aus, erscheint die korrekte Anzahl...
No Comments

Doppelte Emails filtern

4/02/2011
Dieses Skript ist in erster Linie zur Anschauung geschrieben, um einen Eindruck zu bekommen, wie man schnell nach doppelte Einträge suchen kann. Der eigentliche Trick dabei, ist dass die Duplikate nicht direkt via AppleScript sonder über ein standard-Unix-Tool gefunden werden (uniq)

-- hubionmac.com 04.02.2011

-- you say a folder and a search pattern for sender's address

-- and each duplicated email (sender = subject) will be marked, except the latest one

-- I you feel brave you my uncomment the delete 


tell application "Mail" to set thefolder to inbox

set sender_address to "amazon"

tell application "Finder" to set startup_disk to (startup disk as alias) as text


tell application "Mail"

set mysubjects to subject of every message of thefolder whose sender contains sender_address

set AppleScript's text item delimiters to "

"

set mysubjects to mysubjects as text

set AppleScript's text item delimiters to ""

--save this list to a text tmp text file

my writeToFile(startup_disk & "tmp:mail_subjects.txt", mysubjects, false)

--now use the unix tool unig to find all duplicated subjects

--this way because uniq is much faster on comparing thousands of lines than applescript

set duplicated_subjects to do shell script "sort </tmp/mail_subjects.txt | uniq -d | uniq"

do shell script "rm /tmp/mail_subjects.txt"

repeat with mydublicated_subject in (every paragraph of duplicated_subjects)

set current_messages to (every message of thefolder whose subject is mydublicated_subject and sender contains sender_address)

set first_loop to true

repeat with current_message in current_messages

if first_loop is true then

set last_message to current_message

set last_date to date sent of current_message

set first_loop to false

else

if last_date ≤ (date sent of current_message) then

set background color of last_message to green

--delete last_message

set last_message to current_message

set last_date to date sent of current_message

else

set background color of current_message to green

--delete current_message

end if

end if

end repeat

end repeat

end tell



on writeToFile(MacFilePathTxt, txt, add2eof)

--lastedit 18.01.2011

if add2eof is false then

try

do shell script "rm " & quoted form of POSIX path of (MacFilePathTxt as alias)

end try

end if

set RefNum to (open for access file MacFilePathTxt with write permission)

try

if add2eof is false then

write txt to RefNum

else

write txt to RefNum starting at ((get eof RefNum) + 1)

end if

close access RefNum

return true

on error

close access RefNum

return false

end try

end writeToFile

No Comments

Apple Mail: Regel zum Drucken von neuen Nachrichten

22/01/2011

Hier in kleines Skript zum direkten drucken von eintreffenden Nachrichten. Bisher sehe ich nur einen Weg über GUI-Skripting, sollte jemand eine bessere Lösung haben (ausser Quickmail als Client zu verwenden) -->Please comment!

Read the rest of this article »
2 Comments

Mail: angehängte PDFs direkt drucken als Regel…

3/09/2010
Ist eine leicht erweiterte Version dieses Skriptes....

Update 15.02.2011

Wie von Markus gemeldet, werden so keine ausgefüllten Formulare gedruckt... um GUI-Skript zu umgehen wird nun pdftk genutzt um eine druckbare Version zu erstellen, ausserdem wird nun das Druckprogramm ausgeblendet (ist zwar nicht die optimale Lösung, druckt aber zuverlässiger als über lpr via shell scripting)

-- hubionmac.com 2010-09-03

-- script to be added to a Apple Mail rule

--saves PDF attachmens of new mails into a tmp folder and prints them with standard printer

## Update 15.02.2011

## - script now also prints filled pdf forms (requires pdftk to flatten forms)

## - printing app window is hidden after launch (pomps up a milsec... )

on perform_mail_action(info)

tell application "Mail"

tell application "Finder" to set mypath to (name of startup disk & ":tmp:") 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

if current_a_name ends with ".pdf" then

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

save a in mypath & current_a_name

##print pdf form workaround, this requires pdftk installed!!!

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

do shell script "/opt/pdflabs/pdftk/bin/pdftk " & quoted form of POSIX path of ((mypath & current_a_name) as alias) & " output " & POSIX path of ((mypath) as alias) & quoted form of current_a_name2 & " flatten;rm " & quoted form of POSIX path of ((mypath & current_a_name) as alias)

set current_a_name to current_a_name2

##workaround --END--

my print_file_with_standard_printer(POSIX path of ((mypath & current_a_name) as alias))

else

--display dialog current_a_name

end if

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

on getStandardPrinter()

tell application "Printer Setup Utility"

return name of current printer & ".app"

end tell

end getStandardPrinter

on print_file_with_standard_printer(thefile)

-- thefile is a unquoted POSIX path

--assumes that the printer app is stored in ~/Library/Printers/ not /Library/Printers/

tell application (my getStandardPrinter()) to activate

tell application "Mail"

do shell script "open -a ~/Library/Printers/" & quoted form of (my getStandardPrinter()) & " " & quoted form of thefile

##hide the printer app

tell application "Finder" to set visible of process (characters 1 through -5 of (my getStandardPrinter()) as text) to false

end tell

end print_file_with_standard_printer

3 Comments

AppleScript: Email als PDF speichern, mit Attachments

23/03/2010
Mich hat heute eine Email erreicht, in der mir folgende Aufgabe beschrieben wurde (Ich hoffe mal Udo ist mit der Veröffentlichung einverstanden, hätte ich selber nicht besser formulieren können.):
Ich möchte eine Mail in Mail.app anklicken, danach sollte die Mail als pdf (wie unter Ablage Drucken PDF Als PDF sichern) in einem speziellen Ordner auf dem Schreibtisch mit folgendem Namen (Sendedatum, E-Mail-Adresse und Betreff aus Mail) gesichert werden. Der eventuelle Anhang sollte ebenfalls in diesem Ordner gesichert werden. Die Mail kann danach gelöscht werden.
zusammen mit dieser Aufgabenstellung und den ersten Code-Zeilen von Udo ist dann das hier entstanden (ich mag zwar GUI-Scripting nicht, aber das hier ROCKT ;-) ):
Code zum markieren einmal anklicken Code im Skript-Editor öffnen

-- Save Mail as PDF and it's attachments to folder

--  Created by hubionmac (22.03.2010) requested by Udo

global frontmost_message_viewer

--this is the posix (unix) path of the folder you would like to store the messages in

tell application "Finder" to set mymailboxpath to POSIX path of ((desktop) as alias) & "mail_box/"

tell application "Mail"

set myselection to my check_message_viewer_and_return_selection()

--works only with one selected message for many reasons...

if (count of myselection) = 1 then

repeat with currentMail in myselection

set currentSender to my (getEmail(sender of currentMail))

set currentDateSent to my getDatestring(date sent of currentMail)

set currentSubject to my replace_chars(my replace_chars(subject of currentMail, ":", "-"), "/", ":") --Doppelpunkte kommen bei Dateinamen nicht so gut

set currentFolder2Store to mymailboxpath & currentDateSent & " " & currentSender & " " & currentSubject & "/" as text

my create_messagefolder(currentFolder2Store)

repeat with a in (every mail attachment of currentMail)

set current_a_name to name of a

set current_a_name to my checkname_with_pdf_suffix(current_a_name, (POSIX file currentFolder2Store) as alias, false)

save a in (((POSIX file currentFolder2Store) as text) & current_a_name) as text

end repeat

set desktop_pdf_name to my checkname_with_pdf_suffix("1.pdf", path to desktop, false)

set the clipboard to desktop_pdf_name

my print_current_mail_as_pdf()

repeat until (index of window of frontmost_message_viewer) is 1

delay 1

end repeat

my move_desktop_pdf(desktop_pdf_name, currentFolder2Store)

--open destination folder in finder ( did it really work? YES!! =))

do shell script "open " & quoted form of currentFolder2Store

end repeat

else

error "Sorry, ich kann zur Zeit nur mit einer ausgewählten Email hantieren"

end if

end tell

to move_desktop_pdf(desktop_pdf_name, currentFolder2Store)

--used to move the printed pdf to it's final destination

set finalname to checkname_with_pdf_suffix("__message.pdf", (POSIX file currentFolder2Store) as alias, false)

try

tell application "Finder" to do shell script "mv " & POSIX path of ((desktop) as alias) & quoted form of desktop_pdf_name & " " & quoted form of currentFolder2Store & quoted form of finalname

on error msg

error "Fehler beim Bewegen der gedruckten Nachricht:  " & msg as text

end try

end move_desktop_pdf

to getEmail(mailstring)

-- if an email contains the senders name like "Mr.Bla <bla@bla.com>" then returns just the email not leaves the name

if mailstring contains "<" then

return (characters ((offset of "<" in mailstring) + 1) through ((offset of ">" in mailstring) - 1) of mailstring) as text

else

return mailstring

end if

end getEmail

to getDatestring(thedate)

--format a date to a string like 2010-03-22

set monthnum to characters -2 through -1 of ("0" & ((month of thedate) as integer)) as text

set daynum to characters -2 through -1 of ("0" & ((day of thedate) as integer)) as text

set yearnum to year of the thedate

return yearnum & "-" & monthnum & "-" & daynum as text

end getDatestring

to create_messagefolder(thepath_posix)

--I love mkdir -p, simple, short, easy to use

try

do shell script "mkdir -p " & quoted form of thepath_posix

on error msg

error msg

end try

end create_messagefolder

to replace_chars(this_text, search_string, replacement_string)

--this replaces characters

--used for folder and filenames, since a : must not be used for that

if this_text contains the search_string then

set AppleScript's text item delimiters to the search_string

set the item_list to every text item of this_text

set AppleScript's text item delimiters to the replacement_string

set this_text to the item_list as string

set AppleScript's text item delimiters to ""

end if

return this_text

end replace_chars

to checkname_with_pdf_suffix(n, D, looped)

--check if filename exists in D

-- so if "A File.pdf" exists it names it "A File 1.pdf","A File 2.pdf",...

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

to print_current_mail_as_pdf()

--hopefully works on every mac in every language =)

-- GUI-Scripting is not the best way, but somehow the only way at the moment :-/

tell application "Mail"

activate

tell application "System Events"

tell process "Mail"

keystroke "p" using command down

set p to "false"

repeat with i from 1 to 10

if (count of every sheet of window 1) > 0 then

set p to "ready"

exit repeat

end if

delay 1

end repeat

if p = "ready" then

click menu button 1 of sheet 1 of window 1

delay 0.25

key code 125

key code 125

delay 0.25

keystroke return

delay 1

click text field 1 of window 1

keystroke "a" using command down

keystroke "v" using command down

keystroke "d" using command down

keystroke return

else

error "timeout"

end if

end tell

end tell

end tell

end print_current_mail_as_pdf

to check_message_viewer_and_return_selection()

-- check if frontmost window is a message viewer, otherwhise tell the user to RTFM!... wait there is no manual... don't care error change user!

tell application "Mail"

set frontmost_message_viewer to {}

repeat with i from 1 to count of every message viewer

if index of window of message viewer i = 1 then

set frontmost_message_viewer to message viewer i

exit repeat

end if

end repeat

if frontmost_message_viewer = {} then

error "Ist ja gar kein Message Viewer im Vordergrund, so kann ich einfach nicht arbeiten!"

else

return selection

end if

end tell

end check_message_viewer_and_return_selection

In habe mal auf das Löschen der Email verzichtet (das soll mal jeder lieber alleine rein schreiben), aber es scheint wunderbar zu funktionieren. Bin mal gespannt ob es auch bei anderen läuft...Update vom 27.09.2011:

-- Save Mail as PDF and it's attachments to folder

--  Created by hubionmac (29.09.2010)

-- 29.09.2010 

-- -Auswahl von mehren Emails wird nun auch möglich

-- -Abgesendete Emails werden als solche erkannt und in einem anderen Verzeichnis mit Empfänger-Adresse im Ordnernamen gespeichert (req. by Andreas)

-- 27.09.2011 made it work with local mailboxes, too

global frontmost_message_viewer

--this is the posix (unix) path of the folder you would like to store the messages in

tell application "Finder" to set mymailboxpath to POSIX path of ((desktop) as alias) & "received_mail_box/"

tell application "Finder" to set mysentmailboxpath to POSIX path of ((desktop) as alias) & "sent_mail_box/"

tell application "Mail"

set myselection to my check_message_viewer_and_return_selection()

repeat with currentMail in myselection

open currentMail

set currentSender to my (getEmail(sender of currentMail))

set currentDateSent to my getDatestring(date sent of currentMail)

set currentSubject to my replace_chars(my replace_chars(subject of currentMail, ":", "-"), "/", ":") --Doppelpunkte kommen bei Dateinamen nicht so gut

if my is_in_sent_mail(currentMail) is true then

--if the file was sent FROM this email account

set sentToEmail to address of item 1 of to recipient of currentMail

set currentFolder2Store to mysentmailboxpath & sentToEmail & " " & currentDateSent & " " & currentSubject & "/" as rich text

else

--if the email was sent TO this email account 

try

set myemail to item 1 of (get email addresses of account of mailbox of currentMail)

on error

--27.09.2011 added to make it work with local mailboxes, too

set myemail to item 1 of (get address of to recipient of currentMail)

end try

set currentFolder2Store to mymailboxpath & currentDateSent & " " & currentSender & " " & currentSubject & " send to" & myemail & "/" as rich text

end if

my create_messagefolder(currentFolder2Store)

repeat with a in (every mail attachment of currentMail)

set current_a_name to name of a

set current_a_name to my checkname_with_pdf_suffix(current_a_name, (POSIX file currentFolder2Store) as alias, false)

save a in (((POSIX file currentFolder2Store) as rich text) & current_a_name) as rich text

end repeat

set desktop_pdf_name to my checkname_with_pdf_suffix("1.pdf", path to desktop, false)

set the clipboard to desktop_pdf_name

tell application "System Events"

tell process "Mail"

set wc to count of every window

end tell

end tell

my print_current_mail_as_pdf()

tell application "System Events"

tell process "Mail"

repeat until (count of every window) is wc

end repeat

end tell

end tell

my move_desktop_pdf(desktop_pdf_name, currentFolder2Store)

--close last_message window

activate

tell application "System Events"

tell process "Mail"

keystroke "w" using command down

end tell

end tell

--open destination folder in finder ( did it really work? YES!! =))

--do shell script "open " & quoted form of currentFolder2Store

end repeat

end tell

to move_desktop_pdf(desktop_pdf_name, currentFolder2Store)

--used to move the printed pdf to it's final destination

set finalname to checkname_with_pdf_suffix("__message.pdf", (POSIX file currentFolder2Store) as alias, false)

try

tell application "Finder" to do shell script "mv " & POSIX path of ((desktop) as alias) & quoted form of desktop_pdf_name & " " & quoted form of currentFolder2Store & quoted form of finalname

on error msg

error "Fehler beim Bewegen der gedruckten Nachricht:  " & msg as text

end try

end move_desktop_pdf

to getEmail(mailstring)

-- if an email contains the senders name like "Mr.Bla <bla@bla.com>" then returns just the email not leaves the name

if mailstring contains "<" then

return (characters ((offset of "<" in mailstring) + 1) through ((offset of ">" in mailstring) - 1) of mailstring) as text

else

return mailstring

end if

end getEmail

to getDatestring(thedate)

--format a date to a string like 2010-03-22

set monthnum to characters -2 through -1 of ("0" & ((month of thedate) as integer)) as text

set daynum to characters -2 through -1 of ("0" & ((day of thedate) as integer)) as text

set yearnum to year of the thedate

return yearnum & "-" & monthnum & "-" & daynum as text

end getDatestring

to create_messagefolder(thepath_posix)

--I love mkdir -p, simple, short, easy to use

try

do shell script "mkdir -p " & quoted form of thepath_posix

on error msg

error msg

end try

end create_messagefolder

to replace_chars(this_text, search_string, replacement_string)

--this replaces characters

--used for folder and filenames, since a : must not be used for that

if this_text contains the search_string then

set AppleScript's text item delimiters to the search_string

set the item_list to every text item of this_text

set AppleScript's text item delimiters to the replacement_string

set this_text to the item_list as string

set AppleScript's text item delimiters to ""

end if

return this_text

end replace_chars

to checkname_with_pdf_suffix(n, D, looped)

--check if filename exists in D

-- so if "A File.pdf" exists it names it "A File 1.pdf","A File 2.pdf",...

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

to print_current_mail_as_pdf()

--hopefully works on every mac in every language =)

-- GUI-Scripting is not the best way, but somehow the only way at the moment :-/

tell application "Mail"

activate

tell application "System Events"

tell process "Mail"

keystroke "p" using command down

set p to "false"

repeat until 0 = 1

if (count of every sheet of window 1) > 0 then

set p to "ready"

exit repeat

end if

end repeat

if p = "ready" then

click menu button 1 of sheet 1 of window 1

delay 0.25

key code 125

key code 125

delay 0.25

set cwc to count of every window

keystroke return

repeat until 1 = 0

if (cwc + 1) = (count of every window) then

exit repeat

end if

end repeat

click text field 1 of window 1

keystroke "a" using command down

keystroke "v" using command down

keystroke "d" using command down

keystroke return

else

error "timeout"

end if

end tell

end tell

end tell

end print_current_mail_as_pdf

to check_message_viewer_and_return_selection()

-- check if frontmost window is a message viewer, otherwhise tell the user to RTFM!... wait there is no manual... don't care error change user!

tell application "Mail"

set frontmost_message_viewer to {}

repeat with i from 1 to count of every message viewer

if index of window of message viewer i = 1 then

set frontmost_message_viewer to message viewer i

exit repeat

end if

end repeat

if frontmost_message_viewer = {} then

error "Ist ja gar kein Message Viewer im Vordergrund, so kann ich einfach nicht arbeiten!"

else

return selection

end if

end tell

end check_message_viewer_and_return_selection

on is_in_sent_mail(amessage)

tell application "Mail"

set sentmailboxes to every mailbox of sent mailbox

set currentmailbox to mailbox of amessage

repeat with i from 1 to (count of sentmailboxes)

if item i of sentmailboxes = currentmailbox then

return true

end if

end repeat

return false

end tell

end is_in_sent_mail

33 Comments

Automator: Kleines PDF drucken

20/03/2010

Die PDFs die über den normalen Druck-Dialog gedruckt werden, sind pur und unverfälscht, also verdammt groß, wenn man entsprechend viele hochauflösende Bilder im Dokument hat. In Pages kann man PDFs entsprechend "klein" exportieren in Word fehlt aber anscheinend eine solche Funktion und die PDFs die man darüber druckt oder direkt speichert, werden entsprechend groß.
Hinzu kommt, dass man sich das Verzeichnis, in dem die gerade geöffnete Word-Datei steckt, im Sichern-Dialog des PDF-Drucks noch einmal extra suchen darf. Das kann ganz schön nerven, insbesondere meinen Bruder, dem ich hiermit meinen ersten Automator-Workflow widme =)

Man kopiert sich den Workflow in den Ordner "PDF Services" den man im Ordner Library findet (entweder direkt auf der Platte (für alle Nutzer) oder im eigenen Home-Verzeichnis).
Im Druck-Dialog kann man nun neben PDF sichern auch den Workflow PDF_klein auswählen. Auch hier wird nach einem Speicherort gefragt, druckt man aber aus MS-Word wird, in diesem Sichern-Dialog direkt der Ordner des Word-Dokumentes angezeigt. Damit die PDFs nicht unnötig groß werden, werden sie via Automator durch einen Quartz-Filter geschickt, der die Bilder klein rechnet.
Anschließend wird das PDF an eine neue Email angehängt, weshalb sonst der Aufwand =)

DOWNLOAD
PDF_Klein Workflow v.
116.11 KB (176 hits)
No Comments

AppleMail: Sende Email als Attachment einer anderen…

12/02/2010
Ok, die Sinnfrage stelle ich mal nicht. Wenn jemand aber wie z.B. in Thunderbird eine Email nicht als Text, sondern die gesamte Email (Header inkl.) als Attachment verschicken möchte, der könnte eine dieser AppleScript-Funktionen nutzen, um das zu erreichen:
Code zum markieren einmal anklicken Code im Skript-Editor öffnen

on create_mail_emlx_files_attachment_of_selection()

tell application "Mail"

-- get the mail selection

set myMessages to selection

--do it to every selected mail

repeat with m in myMessages

--get the folder where the emlx file is stored in

set mypath to quoted form of POSIX path of ((account directory of account of mailbox of m) as alias)

--get the id of that message (should be unique within each account)

set myid to id of m

--find the folder where this unique email (by id) is stored in

set myfolder to quoted form of (paragraph 1 of (do shell script "find " & mypath & " -name '" & myid & "*.emlx*' -exec dirname {} \\;"))

--create a compressed tar archive of this message and open this gzipped files with Apple Mail (-> attach it to a new message).

do shell script "cd " & myfolder & ";tar -rf " & myid & ".tar " & myid & "*.emlx*;gzip " & myid & ".tar;mv " & myid & ".tar.gz /tmp/;open -a /Applications/Mail.app /tmp/" & myid & ".tar.gz"

end repeat

end tell

end create_mail_emlx_files_attachment_of_selection


on create_mail_source_attachment_of_selection()

tell application "Mail"

-- get the mail selection

set myMessages to selection

--do it to every selected mail

repeat with m in myMessages

set myid to id of m

set mysource to quoted form of ((source of m) as text)

do shell script "cd /tmp/;echo " & mysource & "|cat>/tmp/" & myid & ".txt;gzip " & myid & ".txt;open -a /Applications/Mail.app " & myid & ".txt.gz"

end repeat

end tell

end create_mail_source_attachment_of_selection

No Comments

Apple Mail Datenbanke entschlacken

15/01/2010
Code zum markieren einmal anklicken
osascript -e "tell application \"Mail\" to quit";sqlite3 ~/Library/Mail/Envelope\ Index vacuum index;open /Applications/Mail.app
Im Terminal eingeben (Idee von hier)
No Comments

Mail:Reine Text Email via Skript estellen

9/11/2009
Da gibt es doch glatt keinen Apple-Script-Befehlt zum Erstellen einer reinen Text-Email unter Apple Mail. An dem Punkt setzt dann GUI-Scripting an, das ausführen, was noch die zuvor ein Skript in einem Programm ausgeführt hat...
Nun, das hier als einfaches Beispiel, wie man eine Email in Apple Mail via Skript erstellt und anschließend über GUI-Skripting die Email in reinen Text umwandelt ( der letzte Schritt funnktioniert nur in einem dt. OS, da nach dem Namen des Menüpunktes gesucht wird!).
Code zum markieren einmal anklicken Code im Skript-Editor öffnen

my new_mail("test_betreff", "keinevalideEmailAlsoGarNichtErstVersuchen@hubionmac.com", "Was ich schon immer mal schreibe wollte")


my switch_to_reinen_text()

on new_mail(email_betreff, toadresse, Mail_text)

tell application "Mail"

set newMessage to make new outgoing message with properties {subject:email_betreff as text}

tell newMessage

set visible to true

make new to recipient at beginning of to recipients ¬

with properties {address:toadresse}

set content to Mail_text

--make new cc recipient at beginning of cc recipients ¬

-- with properties {address:ccadresse}

end tell

end tell

end new_mail

on switch_to_reinen_text()

activate application "Mail"

tell application "System Events"

get system attribute "sysv"

if result is greater than or equal to 4144 then -- Mac OS X 10.3.0

if UI elements enabled then

tell application process "Mail"

if (name of menu item 11 of menu 1 of menu bar item 8 of menu bar 1) = "In reinen Text umwandeln" then

keystroke "t" using shift down & command down

end if

end tell

else

beep

display dialog "GUI Scripting is not enabled" & return & return & "Open System Preferences and check Enable Access for Assistive Devices in the Universal Access preference pane, then run this script again." with icon stop

if button returned of result is "OK" then

tell application "System Preferences"

activate

set current pane to pane "com.apple.preference.universalaccess"

end tell

end if

end if

else

beep

display dialog "This computer cannot run this script" & return & return & "The script uses GUI Scripting technology, which requires an upgrade to Mac OS X 10.3 Panther or newer." with icon caution buttons {"Quit"} default button "Quit"

end if

end tell

end switch_to_reinen_text

No Comments