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


Click here to return to the 'Open formatted man pages in Preview from the command line' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Open formatted man pages in Preview from the command line
Authored by: scootermachorn on May 25, '11 02:28:12PM

The following script will open a man page as a PDF in Preview or as a text file in BBEdit, TextWrangler, or TextEdit. Previously converted man pages are stored in "/Users/Shared/Documents/man/" for reference and to save conversion time.

Hope this helps!

<code>
#!/bin/bash
# bbman -- converts man pages to plain text or PDF and opens them in your favorite text editor

## Written by Scott Russell, Information Systems Project Manager, Edward Lowe Foundation
## Last modified: Wed May 25 17:13:15 EDT 2011

ARGS=1
ERR_NOARGS=66

if [ $# -lt $ARGS ] ; then
echo
echo "Usage: `basename $0` < man-page > [pdf]"
echo
exit $ERR_NOARGS
fi

MANTEXT="/Users/Shared/Documents/man"
[[ ! -d "${MANTEXT}" ]] && mkdir -p "${MANTEXT}"

## If we haven't done this before, convert the man page to PDF or text
if [[ `man ${1}` ]] ; then

if [[ "${2}" == "pdf" ]] ; then

if [[ ! -f "${MANTEXT}/${1}.pdf" ]] ; then
man -t "${1}" | pstopdf -o "${MANTEXT}/${1}.pdf" -i -p
fi

## Open in Preview
open -a Preview "${MANTEXT}/${1}.pdf"

else

if [[ ! -f "${MANTEXT}/${1}.txt" ]] ; then
man $1 | col -b > "${MANTEXT}/${1}.txt"
## If SetFile is installed, set the file's creator to R*ch (BBEdit)
[ -f /Developer/Tools/SetFile ] && /Developer/Tools/SetFile -c R*ch "${MANTEXT}/${1}.txt"
fi

## Open in BBEdit or TextWrangler or TextEdit
bbedit "${MANTEXT}/${1}.txt" 2>/dev/null || edit "${MANTEXT}/${1}.txt" 2>/dev/null || open -e "${MANTEXT}/${1}.txt"

fi

fi

exit 0

</code>



[ Reply to This | # ]