Ad

How Can I Send A Document To The System Print Dialog On MacOS?

- 1 answer

I am wondering if there is a way to use the system print dialog on Mac to print PDF documents.

Everything I have seen so far involved either using lpr or was only valid on Windows.

Particularly, once I have the dialog, I would like to change the print options, possibly even selecting the printer-specific "staple" options (on a Xerox WorkCentre).

Ad

Answer

There may be a much better way, but this might get you started:

#!/bin/bash

# Open PDF in Preview app
open FileToPrint.pdf

# Tell Preview to print it
osascript<<EOF
tell application "System Events"
   tell process "Preview"
      delay 1
      keystroke "p" using command down
      --delay 1
      --keystroke return
      --delay 10
      --keystroke "w" using command down
  end tell
end tell
EOF

The lines starting with -- are comments, so remove the -- to actually go ahead and print the document without further interaction being required.

If that open command doesn't happen to open in Preview, you can force it with:

open -a Preview FileToPrint.pdf 
Ad
source: stackoverflow.com
Ad