PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, September 17, 2022

[FIXED] How can I send a document to the system print dialog on MacOS?

 September 17, 2022     macos, printing, python     No comments   

Issue

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).


Solution

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 


Answered By - Mark Setchell
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing