Running man produces zombie speech

Hi. Does “man” via Applescript produce anything useful for you? Here’s a snippet of what running

do shell script "man <any man command here>"

returns on my machine. I’m not sure if this is a version or machine-specific thing, but it’s sort of funny.

"CHFLAGS(1) BSD General Commands Manual CHFLAGS(1)

NNAAMMEE
cchhffllaaggss – change file flags

SSYYNNOOPPSSIISS
cchhffllaaggss [–RR [–HH | --LL | --PP]] _f_l_a_g_s f_i_l_e ...

DDEESSCCRRIIPPTTIIOONN
The cchhffllaaggss utility modifies the file flags of the listed files as speci-
fied by the _f_l_a_g_s operand."

Hello.

The man command really assumes that you are using it from a terminal program, since it formats the manual pages through groff, to simulate bold and italic fonts and what not.

You could however use my gman script, (save it in a folder, chmodu u+x and call it from a do shell script for a nice effect. :slight_smile:

[code]#!/bin/bash

2013 © McUsr and put into public domain, insofar that you don’t post this elsewhere.

if [ $# -lt 1 ] ; then
echo “gman takes a man page, if found and formats it into html.”
echo “Usage: gman [manfile]”
exit 2
fi
a=man -aw $* |head -1 2>&1 >/dev/null
if test x$a = x ; then
echo “Can’t find $1”
exit 1
fi

Figures out if it is a normal man page or something else (gz).

b=man -aw $* |head -1 |grep "gz" 2>&1 >/dev/null
t=mktemp -t gman.1.XXXXXXXXXX
if test x$b = x ; then
groff -mandoc $a -Thtml >|$t.html 2>/dev/null
else
gzcat -f $b |groff -mandoc -Thtml >|$t.html 2>/dev/null
fi
echo |qlmanage -px $t.html 2&>1 >/dev/null &[/code]
Edit

I don’t think this will work in any versions of OS X prior to Snow Leopard.
You should be able to use it to retrieve the formatted html, which you can transform to text with text-util.

The “man” manual itself recommends:

do shell script "man <command> | col -b"

I myself would want to improve the horrible quotes:

do shell script "man <command> | col -b | sed ' s/`/'\\''/g ; s/'\\'\\''/\"/g ;' "

Hello.

Really nice Nigel, I thought it was an easier way to produce text of a man page. Quite more efficient too! I actually started on a script doing what col -b does ( a long time ago), but it was hard to get right.

I believe the reason for the particular quoting is that the page has been pre/post formatted via the m4 (macro (m+4 characters)) macro-processor, where `’ is the standard quotes.

But it is also the traditional quoting in technical documents, at least those originating from Bell Labs.