hi to all,
i’m trying to write a script that edits and prints a group of PDF files.
it could be a droplet or an app, i really don’t care about that right now.
the thing is that i can’t make photoshop print…
i’m able to edit the PDF: what i need is to lower the resolution od the PDF to 100dpi, convert it to graysacle and flatten it. and then, print it, thats the messy part.
when i say this:
tell application "Adobe Photoshop CS2"
print document 1
end tell
photoshop comes to front, and shows me the dialog box for me to select a printer and set it up, and the hit OK to print.
i want this window to never apear, i need zero interaction with the user, 'cause some times i’ll send to print hundreds of PDFs in a row.
i wanted to use automator for this, but hen i downloaded the automator actions for photoshop cs2, i realized that there was no printing action…
any idea on how to do this?
( i’ve tried to tell sys events to keystroke return to press the button, but i think thats kinda messy, and that if the user does something while the script is running, it could keystroke something else and stop the whole process… )
Don’t think you can hide the print dialog from within Photoshop you may have to resort to GUI scripting at that point to click the print button. Another option would be to print your file through something that doesn’t require any interaction… lpr comes to mind.
that’s what i was affraid of… 'cause if i’m not wrong, if i wanted to use some other app to print, i would need to save the edited file with photoshop, and the select that file to print it.
i think i could use imagemagick and do it all with the Terminal, but i want to give a copy of my app/droplet/whatever to all my teammates, and they all have macs without imagemagick or anything like that (just OS X, Adobe, Office and thanks).
that’s why i want the script to be clean, and to have no user interaction.
anyways, if i save the file to the desktop (as a temp), with a specific name, how do i grab it and print it with lpr, and then delete it, before the next file comes up? (my skills with shell are VERY basic)
gave me an idea on how it works… i’d like to print to a remote printer, so i think that with -P i could set the destination, but i can’t figure out a way to find out whats the name of my printer… how can i get a list of the printers from Terminal?
EDIT:
scrolling down sometimes is usefull…
-r will delete the printed file,
and with lpstat -a i found my printers name…
well, thanks James for all the help.
i leave here the finished droplet, and i’m posting it to Code Exchange (maybe someone could find it usefull).
it only needs Adobe Photoshop CS2 & Mac OS X Tiger 10.4.9
on open inputFiles
--set inputFiles to (choose file with prompt "Choose files to print" with multiple selections allowed)
set tempFile to (path to home folder as text) & "tempFile.pdf" --temporary file from wich to print
tell application "Finder" to set sortedFiles to sort inputFiles by name --sort dropped items by name
--flatten, 100dpi max, grayscale, vertical. then print.
repeat with aFile in sortedFiles
tell application "Adobe Photoshop CS2"
set filePath to aFile as string
open alias filePath
tell current document
if layer exists then flatten
if (resolution > 100) then resize image resolution (100 as number)
change mode to grayscale
if (height < width) then rotate canvas angle 90
save as Photoshop PDF in tempFile
close without saving
end tell
end tell
do shell script "lpr -P HP_LaserJet_4000_Series -r " & quoted form of POSIX path of tempFile
end repeat
end open
well…
i claimed victory TOO early.
i now need the printings to fit an A4.
but photoshopCS2 seems to have a problem resizeing images…
i really can’t figure out what’s wrong here… any ideas???
on run inputFiles
set docHeight to 290
set docWidth to 200
set inputFiles to (choose file with prompt "Choose files to print" with multiple selections allowed)
set tempFile to (path to home folder as text) & "tempFile.pdf" --temporary file from wich to print
tell application "Finder" to set sortedFiles to sort inputFiles by name --sort dropped items by name
--flatten, 100dpi max, grayscale, vertical. then print.
repeat with aFile in sortedFiles
tell application "Adobe Photoshop CS2"
activate
set display dialogs to never
set UserPrefs to properties of settings
set ruler units of settings to mm units
set filePath to aFile as string
open alias filePath
tell current document
if layer exists then flatten
if (resolution > 100) then resize image resolution 100 resample method bicubic
change mode to grayscale
if (height < width) then rotate canvas angle 90
if (height > docHeight) then resize image height docHeight resample method bicubic
if (width > docWidth) then resize image width docWidth resample method bicubic
save as Photoshop PDF in tempFile
close without saving
end tell
set ruler units of settings to ruler units of UserPrefs
end tell
do shell script "lpr -P HP_LaserJet_4000_Series -r " & quoted form of POSIX path of tempFile
end repeat
end run
yes, i know about the PDF open thing, but i want to be able to use any kind of file, but to print from a PDF.
any ways, i copied the new lines from a Photoshop script sample… but it still does not work… i mean, it runs, but it takes the image to another size… something like 14cm x 20cm and i don’t know why…
on run inputFiles
set inputFiles to (choose file with prompt "Choose files to print" with multiple selections allowed)
set tempFile to (path to home folder as text) & "tempFile.pdf" --temporary file from wich to print
tell application "Finder" to set sortedFiles to sort inputFiles by name --sort dropped items by name
--flatten, 100dpi max, grayscale, vertical. then print.
repeat with aFile in sortedFiles
tell application "Adobe Photoshop CS2"
activate
set display dialogs to never
set UserPrefs to properties of settings
set filePath to aFile as string
open alias filePath
set ruler units of settings to mm units
set docHeight to height of current document
set docWidth to width of current document
tell current document
if layer exists then flatten
if (resolution > 100) then resize image resolution 100 resample method bicubic
change mode to grayscale
if (height < width) then rotate canvas angle 90
if (docHeight > 780) then resize image current document height 780 as pixels width (780 * docWidth / docHeight) as pixels
if (docWidth > 1740) then resize image current document width 1740 as pixels height (1740 * docHeight / docWidth) as pixels
save as Photoshop PDF in tempFile
close without saving
end tell
set ruler units of settings to ruler units of UserPrefs
end tell
do shell script "lpr -P HP_LaserJet_4000_Series -r " & quoted form of POSIX path of tempFile
end repeat
end run
I had to comment out the finder sort to test. I think thats tiger only? I have put it back though.
on run inputFiles
set inputFiles to (choose file with prompt "Choose files to print" with multiple selections allowed)
-- temporary file from wich to print
set tempFile to (path to desktop from user domain) & "tempFile.pdf" as string
-- sort dropped items by name
tell application "Finder" to set sortedFiles to sort inputFiles by name
-- set up photoshop outside the loop
tell application "Adobe Photoshop CS2"
set display dialogs to never
set UserPrefs to properties of settings
set ruler units of settings to pixel units
end tell
-- flatten, 100dpi max, grayscale, vertical. then print.
repeat with aFile in sortedFiles
tell application "Adobe Photoshop CS2"
activate
set FilePath to aFile as string
open alias FilePath
tell current document
if layer exists then flatten
change mode to grayscale
if (height < width) then rotate canvas angle 90
if (height > 780) then resize image height 780 resolution 100
if (width > 1740) then resize image width 1740 resolution 100
save as Photoshop PDF in tempFile
close without saving
end tell
end tell
do shell script "lpr -P HP_LaserJet_4000_Series -r " & quoted form of POSIX path of tempFile
end repeat
-- set back photoshop outside the loop
tell application "Adobe Photoshop CS2"
set ruler units of settings to ruler units of UserPrefs
end tell
end run