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

Pages: Aktuelle Seite Drucken

3/10/2009
Code zum markieren einmal anklicken Code im Skript-Editor öffnen

-- 03.10.2009 hubionmac.com

-- aktuelle Seite in Pages drucken


if (count of my visible_pages()) > 1 then

set page_to_print to (choose from list (my visible_pages()) with prompt "Welches Seite soll gedruckt werden?")

else

set page_to_print to my visible_pages()

end if



print_page(1, first item of page_to_print, last item of page_to_print)


on print_page(number_of_copies, startpage, stoppage)

tell application "Pages"

activate

tell document 1

--das sollte eigentlich funktionieren... tut es aber bei mir nicht...

--print with properties {copies:1, starting page:3, ending page:3, collating:true} with print dialog

--als GUI-Pfusch:

tell application "System Events"

keystroke "p" using command down

delay 1

keystroke (number_of_copies as text)

keystroke tab

delay 0.25

keystroke (startpage as text)

keystroke tab

delay 0.25

keystroke (stoppage as text)

delay 0.25

keystroke return

end tell

end tell

end tell

end print_page

on visible_pages()

tell application "Pages"

tell window 1

set pagerefs to (visible pages as list)

set page_numbers to {}

repeat with p in pagerefs

set page_numbers to page_numbers & {page number of p}

end repeat

end tell

end tell

return page_numbers

end visible_pages

1 Comment