问题描述:

How can you instruct an application or the printer to only print the first page, a page range or just odd or even pages of a file? I attempt this with the help of the Preview app, which looks promising:

set theFile to "[file-path/file]""

tell application "Preview"

activate

print theFile with properties {target printer:"Printer", ending page:1} without «class pdlg»

--these properties isn't available for the printer app, here just limiting amount of printed pages

quit

end tell

But with this I'm bitten by the sandboxd process that tells me the file can't be opened for printing and I get a deny file-read-data result in the log.

In the CUPS suggestion by adamh I encounter issues with umlauts and have other execution issues as well, possibly also because of sandbox rules. The code works from the command line, but not when called in automated fashion.

I tried to look up useful examples of the print command in a reference, in my books and tried searching the online Apple references, but I can't seem to find many examples fitting to the present day situation with sandbox, if any.

网友答案:

You could script printing by command line tool lp & lpr. These talk to CUPS, Common Unix Printing System

To target pages / ranges:

lp -o page-ranges=2-4 "my_great_document.pdf"

To call it from applescript use do shell script

e.g,

do shell script "lp -o page-ranges=2-4 'my_great_document.pdf'"

For more ideas see: http://www.cups.org/documentation.php/options.html

相关阅读:
Top