The Robservatory

Robservations on everything…


Open PostScript files in Preview in macOS Ventura

One major change in macOS Ventura is that Preview can no longer display PostScript files. Apple hasn't explained why they've made this change, but many think it's due to possible security issues with PostScript files.

Whatever the reason, this change broke one of my most-used Terminal functions:

pman name-of-command

This function opens the specified command's man page in Preview, nicely formatted using PostScript. Or at least, it did. The function itself, as defined in my .profile file, was very simple:

# Open man pages in Preview
function pman()
    man -t "${1}" | open -f -a

But this now fails because Preview won't parse the PostScript file. There are two solutions for this, one that relies on an external package (which is the solution I found), and another using only macOS' built-in tools (which I found just after finishing this writeup).

Built-in solution

The replacement function for my old pman command looks like this:

function pman()
    mandoc -T pdf "$(/usr/bin/man -w [email protected])" | open -fa Preview

Armin Briegel posted the above solution on his blog, Scripting OS X. I've tested it, and it works well—it's the solution I'm using, in fact, because it's much faster than my solution.

External tools solution

Before I found the above-linked page, I found a solution that relies on Ghostscript, which I installed it via Homebrew (brew install ghostscript).

The package contains a number of tools for working with PostScript; the one of interest to me is ps2pdf, which does what you might guess: Converts PostScript files to PDF files. With Ghostscript installed, my slightly more complicated (though still one line) function now looks like this:

# Open man pages in Preview
function pman()
    man -t "${1}" 2>/dev/null | /usr/local/bin/ps2pdf - - | open -f -a

The man command generates the PostScript output (and suppresses any errors), which is then piped to the ps2pdf converter1If you didn't install ps2pdf with homebrew, replace the path above with the proper path on your system., whose command line options indicate that it should accept standard input (the output from the man command) and send its results to standard output, which is then piped to the Preview app.

Either of these will work, but the first method, using only built-in tools, is notably faster. From Armin's blog, I also discovered that you can open any man page in a separate "man page" Terminal window by using the x-man-page URL scheme:

open x-man-page://zsh, open x-man-page://ln, etc.



Add a Comment
  1. Oddly enough I had used exactly this same script, except I called it "manp". Hadn't realized that it was broken, but thanks for the fix

  2. I am pretty sure I learned about opening Mac pages in Terminal on initially. It is a tool I have found to useful to have and share for a long time now, so I love that I could "give it back" this way.

Leave a Reply

Your email address will not be published. Required fields are marked *

The Robservatory © 2022 • Privacy Policy Built from the Frontier theme