I find myself building PDFs by producing single PDFs from various places (using Print to PDF from applications - Safari, Preview, Wor, Pages etc), then assembling the resulting PDFs into a single PDF.
Seems to me this could be simplified enormously by a script which would directly append the PDF output from the Print dialog invoked in the various applicaions into the frontmost PDF open in, say, Skim or Acrobat. That way you could quickly and without fuss build up a composite PDF cutting out the intermediate stages of saving as individual PDFs then assembling later.
Just set up a folder with this script attached as a folder action and bingo!
Everything printed into the folder, via save as PDF from the print dialog, is appended. Just rename the resulting file and move it out of the folder to where you want to keep it.
I have Leopard. Would be nice to know if it works in Snow Leopard. If anyone has Snow Leopard installed…
If you want to make it a simple single button press to append stuff, you can install and set up the Cups-pdf printer to print PDFs to the designated folder. See http://www.codepoetry.net/projects/cups-pdf-for-mosx.
After having said I had the solution, I am running into flaky performance - which may be due to folder action scripts.
Anyway, I have the a script below, adapted from posts. But I think i would be better off with a script that runs from launchd when PDFs are added to a particular folder and builds the combined PDF into another folder (as building the PDF in the same folder retriggers the script). Thus I would like to have a folder containing two subfolders A and B. Throw the PDFs at folder A and they are combined into a PDF saved in folder B.
I have been unable to work the syntax to achieve that by adapting the script below. Any help, gratefully received…
Thanks
property join_py : quoted form of "/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py"
on adding folder items to this_folder after receiving these_items
tell application "System Events" to set last_app to item 1 of (get name of processes whose frontmost is true)
tell application "Finder"
set add_pdfs to ""
set output_pdf to (name of this_folder as Unicode text) & ".pdf"
get name of first item of these_items
if result is output_pdf or result is (output_pdf & "_tmp") then
--beep -- ignore false alarms
else
set output_pdf to (POSIX path of (this_folder as alias)) & output_pdf
repeat with an_item in these_items
set add_pdfs to add_pdfs & space & quoted form of (POSIX path of (an_item as alias))
end repeat
try
--get POSIX file output_pdf as alias -- it exists
set name of result to name of result & "_tmp"
do shell script "python " & join_py & " -o " & (quoted form of output_pdf) & space & (quoted form of (output_pdf & "_tmp")) & add_pdfs
delete (POSIX file (output_pdf & "_tmp") as alias)
on error
try
do shell script "python " & join_py & " -o " & (quoted form of output_pdf) & add_pdfs
on error
my notify(2, "ERROR", last_app)
delete (POSIX file (output_pdf) as alias)
get POSIX file (output_pdf & "_tmp") as alias
set name of result to "CombiPDF.pdf"
repeat with an_item in these_items
delete an_item
end repeat
error -128
end try
end try
repeat with an_item in these_items
set fname to name of an_item
delete an_item
my notify(1, fname as text, last_app)
end repeat
end if
end tell
delay 1
end adding folder items to
on notify(messNum, fileName, appName)
tell application "GrowlHelperApp"
-- Make a list of all the notification types
-- that this script will ever send:
set the allNotificationsList to ¬
{"PDF Added", "PDF Failed"}
-- Make a list of the notifications
-- that will be enabled by default.
-- Those not enabled by default can be enabled later
-- in the 'Applications' tab of the growl prefpane.
set the enabledNotificationsList to {"PDF Added", "PDF Failed"}
-- Register our script with growl.
-- You can optionally (as here) set a default icon
-- for this script's notifications.
register as application ¬
"CombiPDF" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application appName
--Send a Notification...
if messNum is 1 then
notify with name ¬
"PDF Added" title ¬
"CombiPDF" description ¬
"FOLLOWING PDF ADDED:" & return & fileName application name "CombiPDF"
else if messNum is 2 then
notify with name ¬
"PDF Failed" title ¬
"CombiPDF" description ¬
"ADDING PDF FAILED:" & return & fileName application name "CombiPDF"
end if
end tell
end notify
Have now worked out my script as per below. It works much more dependably but if someone has a faster shell script to do the appending, that would help the speed issues which sometimes arise.
property join_py : quoted form of "/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py"
on adding folder items to this_folder after receiving these_items
delay 0.5
tell application "System Events" to set last_app to item 1 of (get name of processes whose frontmost is true) as text
tell application "Finder"
set output_pdf to "CombiPDF.pdf"
--set combiFolder to (path to current user folder as text) & "Documents:CombiPDF:" as alias
--set these_items to every file in combiFolder
set destFolder to (path to current user folder as text) & "Documents:CombiPDFResult:"
set nmbr to (count (these_items))
my notify(3, "", "Colorsync Utility")
set add_pdfs to ""
set output_pdf to (POSIX path of (destFolder as alias)) & output_pdf
repeat with an_item in these_items
set add_pdfs to add_pdfs & space & quoted form of (POSIX path of (an_item as alias))
end repeat
try
get POSIX file output_pdf as alias -- it exists
set name of result to name of result & "_tmp"
do shell script "python " & join_py & " -o " & (quoted form of output_pdf) & space & (quoted form of (output_pdf & "_tmp")) & add_pdfs
delete (POSIX file (output_pdf & "_tmp") as alias)
on error
try
do shell script "python " & join_py & " -o " & (quoted form of output_pdf) & add_pdfs
on error
my notify(2, "ERROR", "Console")
delete (POSIX file (output_pdf) as alias)
get POSIX file (output_pdf & "_tmp") as alias
set name of result to "CombiPDF.pdf"
repeat with an_item in these_items
delete an_item
end repeat
error -128
end try
end try
repeat with an_item in these_items
set fname to name of an_item
my notify(1, fname as text, last_app)
delete an_item
end repeat
if nmbr > 4 then
delay 2
my notify(5, nmbr as text, "Network Utility")
end if
--else
-- my notify(4, "", last_app)
--end if
end tell
end adding folder items to
on notify(messNum, fileName, appName)
tell application "GrowlHelperApp"
-- Make a list of all the notification types
-- that this script will ever send:
set the allNotificationsList to ¬
{"PDF Added", "PDF Failed", "Processing", "No Files", "Total Processed"}
-- Make a list of the notifications
-- that will be enabled by default.
-- Those not enabled by default can be enabled later
-- in the 'Applications' tab of the growl prefpane.
set the enabledNotificationsList to {"PDF Added", "PDF Failed", "Processing", "No Files", "Total Processed"}
-- Register our script with growl.
-- You can optionally (as here) set a default icon
-- for this script's notifications.
register as application ¬
"CombiPDF" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application appName
--Send a Notification...
if messNum is 1 then
notify with name ¬
"PDF Added" title ¬
"CombiPDF" description ¬
"FOLLOWING PDF ADDED:" & return & fileName application name "CombiPDF"
else if messNum is 2 then
notify with name ¬
"PDF Failed" title ¬
"CombiPDF" description ¬
"ADDING PDF FAILED:" & return & fileName application name "CombiPDF"
else if messNum is 3 then
notify with name ¬
"Processing" title ¬
"CombiPDF" description ¬
"Processing PDFs...." application name "CombiPDF"
else if messNum is 4 then
notify with name ¬
"No Files" title ¬
"CombiPDF" description ¬
"No PDFs to process...." application name "CombiPDF"
else if messNum is 5 then
notify with name ¬
"Total Processed" title ¬
"CombiPDF" description ¬
"TOTAL PDFS PROCESSED:" & return & " - " & fileName application name "CombiPDF"
end if
end tell
end notify