Skip to content

Instantly share code, notes, and snippets.

@joeybaumgartner
Last active December 21, 2023 06:23
Show Gist options
  • Save joeybaumgartner/f3675fc2861ca3e47c8ccc29bdfc306e to your computer and use it in GitHub Desktop.
Save joeybaumgartner/f3675fc2861ca3e47c8ccc29bdfc306e to your computer and use it in GitHub Desktop.
Script for opening PDF documents in Preview on macOS Ventura and newer.
#!/bin/sh
if [ $# -lt 1 ]
then
echo “man2pdf [man page name]”
exit
fi
tempfoo=`basename $0`
TMPPDFFILE=`mktemp /tmp/${tempfoo}.XXXXXX` || exit 1
man -t $* | pstopdf -o $TMPPDFFILE
export psStatus=$?
if [ $psStatus -ne 0 ]; then
echo "Could not output contents of man page to temp file"
exit 1
fi
open -a Preview.app $TMPPDFFILE
@joeybaumgartner
Copy link
Author

Before macOS Ventura, you could open any man page in Preview.app with the following command:

man -t <manpage> | open -f -a Preview.app

However, the Preview application in this version of macOS no longer supports opening .ps or .eps files. This script writes the output of man on stdin to pstopdf to a temporary file on disk, and then opens that file in Preview.app.

@joeybaumgartner
Copy link
Author

Made an edit based on this comment from a reddit thread so that you can specify the man section you're interested in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment