PDF: Dynamisches Wasserzeichen mit SVG->PDF Overlay

11/12/2011

Ich habe einen neuen Trick gefunden automatisch PDFs zu erstellen, ohne dabei auf allzu teure (Indesign, Quark), komplizierte (ruby pawn z.B.) oder nicht gerade performante Tools (Pages, Word) angewiesen zu sein. SVG-Dateien sind quasi nichts anderes als XML bzw. Text-Dateien, und lassen sich leicht per Skript manipulieren. Zudem lassen sich auch exakte Format-Angabe (A4, Letter usw.) definieren.

Das Wandeln von SVG in PDF übernimmt dann Inkscape und zwar als Shell-Anwendung. Auf diese Art lassen sich schnell (ohne GUI) PDFs erstellen, die anders als bei der wkpdf-Lösung auch über einen Transparente Hintergrund verfügen.
Ich habe jetzt kein direktes Beispiel zur Hand, verweise aber mal /Applications/Inkscape.app/Contents/Resources/bin/inkscape-bin --help

1 Comment

PDF: Dynamisches Wasserzeichen mit HTML->PDF Overlay

9/12/2011

Bevor ihr weiterlest (Update: 11.12.2011):

Das mit dem HTML-Dokument als Print-Vorlage war nur ein ehr mittelmäßiger Ansatz... glücklicherweise hat sich eine neue Möglichkeit aufgetan, wie man PDFs von einer besseren Formatvorlage (SVG) erstellen kann. Mehr dazu hier

Ich habe eine relative elegante Lösung gefunden, wie man PDFs mit ein paar Tricks mit dynamischen Wasserzeichen versehen kann. Bei der ursprünglichen Aufgabenstellung wollte jemand Daten aus einem Numbers-Sheet auslesen und dementsprechend Logos und Texte als Wasserzeichen zu PDFs hinzufügen.

Das mit dem Wasserzeichen ist ja mit pdftk recht leicht zu bewerkstelligen und auch das abgleichen der Daten mit den PDF-Namen war ein leichtes. Etwas schwieriger war da schon das automatische Layouten der Datensätze in ein PDF. Man kann so etwas bestimmt mit Quark oder Indesign machen, nur stehen mir diese Programme leider nicht zu Verfügung und zudem produzieren die Dinger einen ganz schönen Overhead und der Rechner ist in der Zeit komplett blockiert.

Stattdessen habe ich mir für einen günstigere Variante (php, ruby-> wkpdf) quergedacht, da die PDFs sowieso nur für den Online-Gebrauch erstellt werden sollen und nicht für den Druck.

Read the rest of this article »
1 Comment

ISBN Nummern aus PDFs auslesen

30/04/2011
Ist eigentlich nur ein Beispiel, wie man recht ohne großen Overhead (gs mal vorausgesetzt) PDFs auslesen kann... vielleicht kennt ja jemand noch ein simplere Lösung:

--30.04.2011 hubionmac.com

--quick & dirty script to extract first ISBN-Number of a PDF file... just uses grep, maybe some nice reqexp would do a better job!


set myselection to choose file of type {"pdf"} with multiple selections allowed

set myoutput to ""

repeat with pdf_file in myselection

tell application "Finder" to set pdfname to name of (pdf_file as alias)

set pdf_file_posix to quoted form of POSIX path of (pdf_file as alias)

do shell script ""

try

--first add the path, otherwhise s2ascii will fail since it cannot find ghostscript (gs) which is also installed in /usr/local/bin (think by macports)

set ISBN_String to do shell script "PATH=\"$PATH:/usr/local/bin\"; /usr/local/bin/ps2ascii " & pdf_file_posix & " | grep -m 1 ISBN"

set foundLine to true

on error

display dialog "maybe \"" & pdfname & "\" does not contain a ISBN at all"

set foundLine to false

end try

if foundLine is true then

repeat with s in every word of ISBN_String

try

get s as integer

set s to s as text

set foundisbn to true

exit repeat

on error

set s to ""

end try

end repeat

end if

set myoutput to myoutput & pdfname & tab & s & return

end repeat


tell application "TextEdit"

activate

set a to make new document

set text of a to myoutput as text

end tell

No Comments

Web-Screenshot via Script

25/01/2011
Dazu gibt es recht wenig zu sagen... es erspart einem einige Klicks und man kann dabei weiter surfen... Read the rest of this article »
No Comments

Mail-Regel: Links laden und als PDF abspeichern

5/10/2010
Julien hat mich heute gebeten eine Möglichkeit zu finden, die Links einer Email aufzurufen und die entsprechenden Websites als PDF zu drucken. Bei der Suche nach einer Lösung bin ich auf wkpdf gestoßen. Das ist ein Ruby-Script mit dem man eine URL über das Webkit-Framework lädt und den Output als PDF abspeichern kann. Da die Installation von wkpdf so simple ist und danach einfach via do shell script abrufbar ist, eine perfekte Lösung. Als Anhang (weil durch einen sed-Befehl einige besonders besondere Sonderzeichen im Quellcode stehen). DOWNLOAD
mail_links_to_pdf v.0.1
7.36 kB (133 hits)

Anwendung

Das Skript über eine Mail-Regel anfeuern und jede Email, die auf die Mail-Regel anspringt, wird nach URLs gescannt, die URLs werden über wkpdf aufgerufen und als PDF gespeichert.

Nice2Know

Das Skript nutzt als Email-Text zur Zeit set mytext to content of thisMessage, man könnte aber auch (um auch html-Emails verarbeiten zu können set mytext to source of thisMessage auskommentieren.

Links

3 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

PDF Wasserzeichen die II 1/2.

14/05/2010

Die Sache mit den Ordner-Aktionen war zwar ganz nett, aber nicht wirklich die zuverlässigste Lösung den Vorgang anzustoßen. Aus diesem Grund habe ich einen kleinen Automator-Workflow gebaut, der zuverlässig das Wasserzeichen (via pdftk) einbaut. So kommt das ganze Ding dann auch mit Sonderzeichen im letztendlichen Dateinamen klar. Der Workflow funktioniert unter 10.5 und 10.6. Zur Installation einfach in /Library/PDF Services/ kopieren und von nun an kann in jedem Druckdialog "PDF pdftk" ausgewählt werden.
Der Workflow fragt nach einem Dateinamen und erstellt das fertige PDF mit dem Dateinamen in einen Ordner "Watermarked PDFs" auf dem Schreibtisch. Sollte ein Dateiname bereits vorhanden sein, wird in Finder-Art durch-nummeriert. Am Ende noch ein kurzer Dialog, ob das erstellte PDF gleich an eine neue Email gehängt werden soll. Fertig =) Das Feintuning bleibt jedem selbst überlassen. Damit der Workflow funktioniert, muss aber pdftk installiert sein, einfach von hier die fertig kompilierte Version (zusammen mit den Ordneraktion) laden. (Das Hintergrund-PDF sucht sich das Skript direkt auf dem Startvolumen (_PDF_BACKGROUND.pdf)DOWNLOAD
PDFTK Wasserzeichen (Print-Workflow) v.1.0
156.44 KB (271 hits)

DOWNLOAD
PDFTK Wasserzeichen (Print-Workflow) v.1.1
65.16 kB (96 hits)

Update 15.02.2011

Für Snow Leopard gibt es mittlerweile eine fertig kompilierte Versino direkt vom "Hersteller" von pdftk

Update 16.06.2011

Ich habe den Pfad in dem Skript noch einmal angepasst, so dass er auch mit der aktuellen Version von pdftk funktioniert (/opt/pdflabs/pdftk/bin/pdftk)

3 Comments

UNIX: man page mania

22/04/2010

Gerade heute ist mir mal wieder ein Terminal-Kommando gezeigt worden welches ich noch nicht kannte und da fragte ich wie ich denn wohl selber auf so etwas kommen könnte. Nun, die Infos darüber findet man in den man-pages.

Jetzt könnte man also beigehen und mit man -k --suchstring-- danach suchen lassen, auch apropos --suchstring-- hilft da weiter.
In meinem speziellen Fall ging es aber um afplay (eine Möglichkeit um via Terminal Musik/Töne abzuspielen), wo apropos bzw. whatis versagten. Da erinnerte ich mich an Kommando-Zeile, die ich vor Eweigkeiten mal gefunden hatte, die einem eine Liste aller Terminal-Befehle mit Erläuterung ausgibt: echo $PATH | sed -e 's/:/ /g' | xargs -J % find % -maxdepth 1 \( -type f -or -type l \) | xargs basename | sort | uniq | xargs whatis 2> /dev/null | grep -E '\((1|1m|6|8)\)' | perl -ne '($name, $descrip) = m/^(.*?)\s+- (.*)$/; $name =~ s/\((1|1m|6|8)\)//g; printf("%-20s - %s\n", $name, $descrip)' >apropos_all.txt Nur zapft die eben die whatis-Datenbank an, die bei afplay nicht fand, obwohl es eine man-page dazu gibt. Ich bin jetzt nicht der absolute Terminal-Crack, der sed und awk im Schlaf beherrscht, aber das diese abgeänderte Version schafft es wohl ALLE man-pages-Einträge zu listen. for i in `echo $PATH | sed -e 's/:/ /g' | xargs -J % find % -maxdepth 1 \( -type f -or -type l \) | xargs basename | sort | uniq`;do man $i 2> /dev/null| col -b | head -n 10 | tail -8 |grep "$i" | head -n 1;done >all_bin_info.txt (lässt man übrigens den restlichen Code nach dem uniq weg, bekommt man ein Liste aller verfügbaren Terminal-Befehle)
Übrigens ein netter Trick sich eine Man-Page als PDF ausgeben zu lassen: man -t pstopdf col man | col -b | pstopdf -i -o man.pdf oder als fertiges Bash-Script, dem man einfach als Parameter den Namen des Befehls mitgibt: #/bin/bash man -t $1 groff | col -b | pstopdf -i -o ~/Desktop/$1.pdf;open -a /Applications/Preview.app ~/Desktop/$1.pdf;
2 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

AppleScript: PDFs verkleinern – Droplet

22/03/2010
Das ist quasi die Vorstufe von dem Automator Skript gewesen... Nutzt sips zum verkleinern der Dateien. Hier also der Code des Skript-Droplets:
Code zum markieren einmal anklicken Code im Skript-Editor öffnen

on open these

repeat with this in these

tell application "Finder"

if name of this ends with ".pdf" then

set newname to (characters 1 through -5 of ((name of this) as text)) as text

set newname to newname & "_mail.pdf"

do shell script "sips -s format pdf -s dpiHeight 72 -s dpiWidth 72 -s formatOptions low " & quoted form of POSIX path of this & " " & "--out " & quoted form of POSIX path of ((container of this) as alias) & quoted form of newname

end if

end tell

end repeat

end open

3 Comments