Dear All,
I’m trying to make a script to print just a range of pages of a pdf file. I’m using Preview to open the files (I don’t want to use the Acrobat Reader).
I can send a “print” instruction for the whole document but I don’t know how to print just a range of pages (page 1 trough 2, for example).
I’m new to Applescript, so any help would be appreciated.
What I’ve done so far:
tell application "Printer Setup Utility"
set current printer to first printer whose name is "Samsung SCX-4824 Series (SEC0015992BCCAF)"
end tell
tell application "Preview"
activate
print document 1
end tell
Model: MacBook Pro
AppleScript: 2.0.1
Browser: Firefox 3.0.5
Operating System: Mac OS X (10.5)
Hi zorglubix,
If you need to print PDF documents on Mac OS X, this is most easily done with the «lp» command on the command line.
For example, the following script will print all PDF documents found on the desktop with the default printer, but only from page 3 to 5:
on run
tell application "Finder"
set pdffiles to every file whose name ends with ".pdf"
end tell
if pdffiles is not {} then
repeat with pdffile in pdffiles
set command to "lp -P 3-5 " & quoted form of (POSIX path of (pdffile as alias))
do shell script command
end repeat
end if
end run
If you need to address a certain printer, then you need to include the «-d» option of the «lp» command. To see the name of the available printers, you can enter the following command on the command line:
lpstat -p
Hope that helps!
Hi Martin,
Thank you so much for your help. I’ve just added the flag “-d” to define which printer to use and “-o media=A4” for paper size. This way I can print the first two pages to a color printer and the third and fourth to a B/W one.
set command to "lp -d HP_Color_LaserJet_2600n -o media=A4 -P 1-2 " & quoted form of (POSIX path of (path_to_file as alias))
do shell script command
set command to "lp -d Samsung_SCX_4824_Series__SEC0015992BCCAF_ -o media=A4 -P 3-4 " & quoted form of (POSIX path of (path_to_file as alias))
do shell script command
Thank you once again.