Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the '10.4: Use Preview to view formatted man pages' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: Use Preview to view formatted man pages
Authored by: emailboy on May 21, '08 08:56:12AM

I modified the scripts and suggestions to save the converted PDF in the caches directory, and to check there first. If the file exists, it is opened instead of converting another:


# Opens man pages in Preview.
# The '-t' option to 'man' generates PostScript, which
# Preview can open.  However, Preview needs to first
# convert to PDF, which can take a while.  Hence, we
# save generated pages in a cache directory, and look
# there first.  Also, this allows us to save the page
# with the 'man' entry as its name, which causes the
# Preview window to have that title.

if [ $# -eq 0 ]; then
    X=$(basename "$0")
    echo "$X: opens man pages in Preview"
    echo "Usage: $X man parameters" 
    exit 1

# Cache directory.  Change to taste.

# man page is last parameter, which is tricky to get
eval man=$$#

# file to save man page as PDF

# Create cache directory for 'man' output
mkdir -p "$cachdir"

# If desired PDF man page is in cache, open it
if [ -f "$manfile" ]; then
    open -a Preview "$manfile"
    # Invoke 'man' to check if man page exists, and if so,
    # invoke man to format it to PS, pipe PS output to pstopdf,
    # save result in cache
    man -w $* >/dev/null
    if [ $? -eq 0 ]; then
        man -t $* | pstopdf -o "$manfile" -i
        open -a Preview "$manfile"

[ Reply to This | # ]