December 23, 2023
Apple removed support for PostScript in macOS Sonoma, which has broken a number of things in my daily workflow. Here is a quick roundup post of some of my workarounds.
First, install Homebrew if you don’t already have it.
Now, install the Ghostscript PostScript interpreter:
brew install ghostscript
To confirm that it has installed correctly, open a Terminal and type:
gs --version
You should see something like 10.02.1
.
I have added this to my .zshrc
but it should work just as well in
.bash_profile
and similar.
function manp() { [ -n "$1" ] && man -t $1 | gs -sDEVICE=pdfwrite -o $TMPDIR/$1.pdf - && open $TMPDIR/$1.pdf && sleep 1 && rm $TMPDIR/$1.pdf }
Now you can type manp
instead of man
to view your man pages as a nicely formatted PDF in Preview.
Emacs depends on the system lpr
utility to print PostScript and as of
macOS Sonoma, lpr no longer supports PostScript. The specific error
message you will see is:
user-error: Spooling...done: /usr/bin/lpr: Unsupported document-format “application/postscript”.
Let’s create our own lpr
alternative for Emacs to use.
In a convenient executable folder (in my case, /Users/gene/bin
), create the following file and call it lpr-ps
#!/bin/bash uuid=$(uuidgen) gs -sDEVICE=pdfwrite -o $TMPDIR/$uuid.pdf - && open $TMPDIR/$uuid.pdf && sleep 1 && rm $TMPDIR/$uuid.pdf
Make it executable:
chmod +x /Users/gene/bin/lpr-ps
Add the following to your Emacs configuration (with your particular path of course):
(setq ps-lpr-command "/Users/gene/bin/lpr-ps")
PostScript Print Buffer and PostScript Print Region (M-x ps-print-buffer
and M-x ps-print-region
) should now open a nicely formatted Preview document for you.
NOTE: if you are getting an error like The file … couldn’t be opened because there is no such file. Try changing sleep 1
to a bigger number of seconds, like sleep 10
or even sleep 30
. The script tries to delete the generated temporary file as soon as possible, but sometimes this is sooner than Preview can get it onto the screen. Keep bumping this number up until the script is reliable for you. The tradeoff is that control isn’t returned to Emacs until the full sleep timeout has elapsed.
This might not be an issue for you, but if you use Org’s export to PDF
via LaTeX I had to make the following additional change to my Emacs
config. Something about pdflatex
not being a known LaTeX compiler.
(setq org-latex-pdf-process '("latexmk -f -pdf -interaction=nonstopmode -output-directory=%o %f"))
I’ll continue updating this post with additional PostScript-on-Mac workarounds as I find and implement them.