Hello very new to this and not sure what i’m doing. got as far as opening a pdf and the print box in acrobat but can getthe script it to press the return/enter button to print it. tired the keycode 36 but no joy.
What i ideally want is a script that i could run on a hot folder and when i put the pdfs into it would print them using the acrobat print settings i have saved in acrobat.
All i want to do is open a load of pdfs in acrobat pro and print them
sound easy
Below is my attempt at writing some code. apologies to all you programmers out there. im just a designer
tell application "Finder"
activate
set target of Finder window 1 to folder "Desktop" of folder "sdonovan" of folder "Users" of startup disk
open document file "p032_AN_mar_11.pdf" of folder "Desktop" of folder "sdonovan" of folder "Users" of startup disk
tell application "System Events" to keystroke "p" using {command down}
delay 3
key code 36
end tell
end run
I use the following:… (I’m sure this came from a search of this forum. Sorry can’t remember who to thank for this script!!)
-- Record the current printer and set printer choice
tell application "Printer Setup Utility"
activate
set Default_Printer to the current printer
delay 0.5
quit
end tell
-- Record the system default paper size
set Default_Paper to do shell script "defaults read com.apple.print.PrintingPrefs DefaultPaperID"
-- Adobe uses system prefs for print set up on launch
-- Flush any user changes made after this by quit & re-launch
tell application "System Events"
if exists process "Acrobat" then
tell application "Adobe Acrobat Professional"
quit saving ask
end tell
end if
end tell
-- Get list of PDF's
set Question to "Do you want to include all the subfolders" & return & "within your folder selection?"
set The_Dialog to display dialog Question buttons {"No", "Yes"} default button 1 with icon note
if button returned of The_Dialog is "Yes" then
set Input_Folder to choose folder with prompt "Where is the top level folder of PFD's?" without invisibles
tell application "Finder"
try
set File_List to (files of entire contents of Input_Folder whose name extension is "pdf") as alias list
on error -- only one file
set File_List to (files of entire contents of Input_Folder whose name extension is "pdf") as alias as list
end try
end tell
else
tell application "Finder"
set Input_Folder to choose folder with prompt "Where is the folder of PFD's?" without invisibles
try
set File_List to (file of Input_Folder whose name extension is "pdf") as alias list
on error -- only one file
set File_List to (files of Input_Folder whose name extension is "pdf") as list
end try
end tell
end if
set PDF_Count to count of File_List
if PDF_Count = 0 then
display dialog "Your folder selection contains no PDF files to print!" giving up after 2
end if
-- Loop through the list of files
repeat with this_file in File_List
tell application "Adobe Acrobat Professional"
activate
open this_file
tell active doc
set view mode to just pages
set zoom type of PDF Window 1 to fit page
delay 1
set MB_Size to media box of page 1 as list
-- Points to millimeters Conversion
set MB_Height to ((item 2 of MB_Size) / 2.834645) as integer
set MB_Width to ((item 3 of MB_Size) / 2.834645) as integer
-- Determine long & short edges
if MB_Height ≥ MB_Width then
set LE to MB_Height
set SE to MB_Width
else
set LE to MB_Width
set SE to MB_Height
end if
-- Count the pages this is to be used in the print range
set Page_Count to count of pages
set This_Fit to false
-- Fits on A5 paper (less printer margins)
if LE < 200 and SE < 138.5 then
set This_Fit to true
do shell script "defaults write com.apple.print.PrintingPrefs DefaultPaperID iso-a5"
delay 1
print pages first 1 last Page_Count PS Level 3 with binary output
end if
-- Fits on A4 paper (less printer margins)
if LE < 287 and SE ≤ 200 and This_Fit is false then
set This_Fit to true
do shell script "defaults write com.apple.print.PrintingPrefs DefaultPaperID iso-a4"
delay 1
print pages first 1 last Page_Count PS Level 3 with binary output
end if
-- Fits on A3 paper (less printer margins)
if LE < 410 and SE ≤ 287 and This_Fit is false then
do shell script "defaults write com.apple.print.PrintingPrefs DefaultPaperID iso-a3"
delay 1
print pages first 1 last Page_Count PS Level 3 with binary output
end if
-- Scale output to fit on A3 paper (less printer margins)
if LE ≥ 410 or SE > 287 then
do shell script "defaults write com.apple.print.PrintingPrefs DefaultPaperID iso-a3"
delay 1
print pages first 1 last Page_Count PS Level 3 with binary output and shrink to fit
end if
end tell
close active doc saving no
end tell
end repeat
-- Set the printer choice back
tell application "Printer Setup Utility"
-- activate
set current printer to Default_Printer
delay 0.5
quit
end tell
-- Set the system default paper size back
do shell script "defaults write com.apple.print.PrintingPrefs DefaultPaperID " & Default_Paper
Save this as an app, double click and you will be asked to locate your folder of PDFs to print
Seems like a loading error of the application. Stop script editor, restart acrobat professional and startup script editor again. I have such errors very common with QuarkXPress
quit out of all apps and tried running it again.
it seems to want to open acrobat reader instead of acrobat pro. so the first warning sign i get is do i want acrobat reader as my default app when opening pdfs instead of acrobat pro.
Excellent now got the code to work by cutting out bits.
just need to alter it so it so it looks in a hot folder called say “pdfs to print” then runs automatically when ever any pdfs are put in said folder. below is my working code what do i need to do to get it to look into a folder automatically instead of clicking on the app icon and searching for the folder manually. hope you can help
-- Get list of PDF's
set Question to "Do you want to include all the subfolders" & return & "within your folder selection?"
set The_Dialog to display dialog Question buttons {"No", "Yes"} default button 1 with icon note
if button returned of The_Dialog is "Yes" then
set Input_Folder to choose folder with prompt "Where is the top level folder of PFD's?" without invisibles
tell application "Finder"
try
set File_List to (files of entire contents of Input_Folder whose name extension is "pdf") as alias list
on error -- only one file
set File_List to (files of entire contents of Input_Folder whose name extension is "pdf") as alias as list
end try
end tell
else
tell application "Finder"
set Input_Folder to choose folder with prompt "Where is the folder of PFD's?" without invisibles
try
set File_List to (file of Input_Folder whose name extension is "pdf") as alias list
on error -- only one file
set File_List to (files of Input_Folder whose name extension is "pdf") as list
end try
end tell
end if
set PDF_Count to count of File_List
if PDF_Count = 0 then
display dialog "Your folder selection contains no PDF files to print!" giving up after 2
end if
-- Loop through the list of files
repeat with this_file in File_List
tell application "Adobe Acrobat Pro"
activate
open this_file
tell active doc
set view mode to just pages
set zoom type of PDF Window 1 to fit page
delay 1
set MB_Size to media box of page 1 as list
-- Points to millimeters Conversion
set MB_Height to ((item 2 of MB_Size) / 2.834645) as integer
set MB_Width to ((item 3 of MB_Size) / 2.834645) as integer
-- Determine long & short edges
if MB_Height ≥ MB_Width then
set LE to MB_Height
set SE to MB_Width
else
set LE to MB_Width
set SE to MB_Height
end if
-- Count the pages this is to be used in the print range
set Page_Count to count of pages
set This_Fit to false
-- Fits on A5 paper (less printer margins)
if LE < 200 and SE < 138.5 then
set This_Fit to true
do shell script "defaults write com.apple.print.PrintingPrefs DefaultPaperID iso-a5"
delay 1
print pages first 1 last Page_Count PS Level 3 with binary output
end if
-- Fits on A4 paper (less printer margins)
if LE < 287 and SE ≤ 200 and This_Fit is false then
set This_Fit to true
do shell script "defaults write com.apple.print.PrintingPrefs DefaultPaperID iso-a4"
delay 1
print pages first 1 last Page_Count PS Level 3 with binary output
end if
-- Fits on A3 paper (less printer margins)
if LE < 410 and SE ≤ 287 and This_Fit is false then
do shell script "defaults write com.apple.print.PrintingPrefs DefaultPaperID iso-a3"
delay 1
print pages first 1 last Page_Count PS Level 3 with binary output
end if
-- Scale output to fit on A3 paper (less printer margins)
if LE ≥ 410 or SE > 287 then
do shell script "defaults write com.apple.print.PrintingPrefs DefaultPaperID iso-a3"
delay 1
print pages first 1 last Page_Count PS Level 3 with binary output and shrink to fit
end if
end tell
close active doc saving no
end tell
end repeat