instant alert on replacing/overwriting a file in a folder

Hello.

Here is an alternative for converting man pages to html. I use Safari to look at html instead of pdf.

Prerequisites

man -aw : finds path to the specified man pages:

Example

man -aw launchd.plist
→ launchd.plist.5.gz

launchd.plist is a file with a gz extension,and not just a number like 1,2,3… and so on, so we’ll have to open it with gzcat and pipe the input into groff.

If we hadn’t have to do that, then the commandline would have looked like this:

 groff -man /usr/share/man//man5/launchd.plist.5 -Thtml  >|~/Desktop/tmp.html && open -a "Safari" ~/Desktop/tmp.html

But we have to use this:

 gzcat /usr/share/man//man5/launchd.plist.5.gz |groff -man  -Thtml >|~/Desktop/tmp.html && open -a "Safari" ~/Desktop/tmp.html

The -man parameter tells groff the input/file should be parsed with the man macro package, the -Thtml tells it that it should generate html as output.

Edit

I think it is worth mentioning in the passing, that you shouldn’t regard the man file, as the primary source for information, when it is about tools from the GNU platform. According to the GNU coding standard, you needn’t update the man files, nor that they be accurate. So, when you see a reference to an “info file”, then you should really use that info file as the source of information for a command. At least on Snow Leopard, not all info files are shipped with the OS. Then you can find them over at gnu.org.

(This doesn’t relate to launchd.plist, or tools Apple develops I guess, but it is worth noting, that there is not a word on the sleep.1 man page for instance, that you can indeed specify a decimal value for specifying a fraction of a second.)

Before going to GNU I would take a look at freebsd.org first. Those manuals at freeBSD matches with Mac OS X, Mac OS X is built on FreeBSD 5 till today not on GNU/Linux.

As this is (still) an AppleScript board, I’m reading man pages online at apple.com using this script


property baseURL : "https://developer.apple.com/library/mac/#documentation/darwin/reference/manpages/man"

display dialog "Enter page name (optional with section in parentheses)" default answer "cp" buttons {"Cancel", "OK"} default button "OK"
set manCommand to text returned of result
set leftParenthesisOffset to offset of "(" in manCommand
if leftParenthesisOffset = 0 then
	set section to word 2 of (do shell script "man " & manCommand)
else
	set rightParenthesisOffset to offset of ")" in manCommand
	set section to text (leftParenthesisOffset + 1) thru (rightParenthesisOffset - 1) of manCommand
	set manCommand to text 1 thru (leftParenthesisOffset - 1) of manCommand
end if
open location baseURL & section & "/" & manCommand & "." & section & ".html"


Agreed. :smiley:

I like to use bwana at times. And I also have a script that feeds the man pages from Developer.doc.

It also happens that I use Preview, it all comes down to which window configuration I am happy with at the moment.

It might be, that I have installed utilities that have overwritten the originals, through MacPorts, or something else, but when stuff refer to info, then it is originally from GNU, or is it? Maybe info has crossed over to FreeBSD?

As for FreeBSD v. 5 FreeBSD, along with Xinu, NetBSD, Mach and NextStep is correct, but the version would be 4.3 wouldn’t it? Or is that just for the kernel? (originally). Does to the tools descend from FreeBSD v5?

By the way, how do you make open open header files with something different than XCode? ”And Apple.OpenSource has actually good a good job, improving the codebase of some of the FreeBSD libraries. Just mentioning it, since we are all so quick to complain. :slight_smile:

A good example of things that have originated from GNU that ships with Mac Os X, is the C compiler (gcc not clang). :smiley:

Actually FreeBSD is much better in reliability and performance. Sony, Yahoo and Hotmail run their servers on FreeBSD because of that. FreeBSD did copy new features from Darwin, but they did it better and not simply copy paste.

Hi Stefan,
I do like the convenience of the script, as well as the Apple man pages. Their layout is great, with easy navigation via links. The only thing I’m puzzled about, is that they still haven’t updated from 10.7.4. Why? Does it matter?

Cheers,
Chris

Hello.

I actually thought I’d make my stint for turning a random manpage into html into an applescript but it doesn’t seem necessary to do so. :slight_smile:

[code]#!/bin/bash
argc=$#
if [ $argc -lt 1 ] ; then
echo “gman takes a man page, if found and formats it into html.”
echo “Usage: gman [-s1…n|-s 1…n] manfile”
exit 2
fi
a=man -aw $* 2>/dev/null|head -1 2>&1 >/dev/null
if test x$a = x ; then
if [ $argc -eq 1 ] ; then
echo “gman: Can’t find $1”
exit 1
elif [ $argc -eq 2 ] ; then
echo “gman: Can’t find $2 in section ${1#-s}, try another section.”
exit 1
elif [ $argc -eq 3 ] ; then
echo “gman: Can’t find $3 in section $2, try another section.”
exit 1
else
echo “gman: “$*” didn’t work for me.”
exit 1
fi
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]
Put it somewhere in your path, make it exexutable and try: gman launchd.plist for instance in a terminal window. :slight_smile:

Hi guys, I combined DJ’s command at #12 with Stefan’s script at #16 to allow for access without the terminal and optional sections, as well as an attempt to comply with Stefan’s implied urging :wink:

-- Apple freeBSD man pages, local, pdf
-- opens local man pages in Preview as pdf.
-- using scripts by DJ Bazzie Wazzie at #12 and by StefanK at #16 in http://macscripter.net/viewtopic.php?pid=160863#p160863
display dialog "Enter the page name" & return & "(optional with section in parentheses)" default answer "mv(1)" with title "Apple freeBSD man pages, local, pdf" buttons {"Cancel", "OK"} default button 2
set manCommand to text returned of result
set leftParenthesisOffset to offset of "(" in manCommand
if leftParenthesisOffset = 0 then
    do shell script "man -t " & manCommand & " | open -f -a preview"
else
    set rightParenthesisOffset to offset of ")" in manCommand
    set section to text (leftParenthesisOffset + 1) thru (rightParenthesisOffset - 1) of manCommand
    set manCommand to text 1 thru (leftParenthesisOffset - 1) of manCommand
    do shell script "man -t " & manCommand & " | open -f -a preview"
end if

Hi McUsrII,

I tried the bash script but, I can’t make it work. I copied the script to a UTF-8 text file, saved it to the desktop as gman, and did chmod u+x gman in the terminal. Then, I entered gman launchd.plist. I got this: -bash: gman: command not found.
What am I doing wrong?

Hello.

You can cd ~/Desktop and issue: ./gman launchd.plist (or any other command!)

You can also start it by: ~/Desktop/gman launchd.plist

If you like it, then I recommend you install it somewhere, instructions follow below:

Try echo $PATH in your terminal window, copy gman to one of the folders that are showing up when you do that command. the folder should be local, so if you haven’t ~/bin in your PATH variable, then try this in your .bashrc file:

PATH=~/bin:$PATH

After any other PATH statements you may have. And if you don’t have a .bashrc file, then look for .profile or .bash.profile in your $HOME folder.

And copy gman to that folder before you cd somewhere else, and see if it works. I hope you like it. :slight_smile:

That’s exactly what I did before. I tried that again and got this:

Mac-1:desktop chris$ ./gman launchd.plist -bash: ./gman: /bin/bash¨if: bad interpreter: No such file or directory
I tried again from scratch, copying your code and so on. ”> no change.
Then it occurred to me that your posted code may have some extraneous end of line characters, and created the text file again by copying just the visible characters on each line. A bit tedious but ”> SUCCESS :wink:
I think that either you used some funny editor (unlikely) or, the forum’s code tags are playing jokes. Anyway, it works now. Many thanks :smiley:

I put it on the desktop just for testing. Once it works, I have a place for all my command line tools.

Cheers, Chris

Do you have linefeed as line terminators and not returns? because of the “/bin/bashif” error it seems that the line terminator is wrong.

Sorry DJ, I don’t have the bad text file any longer. On my successful try, when I copies just the visible characters, I just typed returns.

Hello.

Do yourself a favor and get TextWrangler if you don’t have, then you can save the file with encoding utf-8 No BOM, and with unix linefeeds.

Just did and retired TextEdit from scripting duties :wink:

Good for you1 :smiley:

By the way, when having gman display a webpage: Have you tried to click on one of the generated links? :wink:

Try gman bash and then click on one of the links at the top if you click on NAME for instance, it’ll open in Safari, or your default browser I guess.

If you’re not comfortable with textWrangler yet, you should definitely take a look at Sublime Text 2. In my opinion the best text editor (for developers) available on the Mac

Hello :smiley:

I have standardized on vi for heavy chores, but this is not for everybody.

I use Iterm, and vim, I have full syntax completion for both C and Objective-C and C++ thanks to LLVM.org and very nifty plugin named youcompleteme. Together with all the nice stuff. C-tags and cscope, so I can navigate all the ways I want, also back and forth between visited places in the code.
I move easily in the error list, I cand do a grep in my project source, and move back and forth in that list, tracing stuff. GDB is integrated, so I can watch the code while I trace.

vim is incredibly fast to use, and as compatible with applescript as sublime I guess. But you have to know your way around, to leverage upon this of course.

But I am so happy with vi and iTerm nowadays, that I can’t express it. Not substitute for XCode of course, but I can have both.

There is a downside however, and that is that I tend to get strings with jjjjjjjjjj,s hhhhhhhhhhhh’s kkkkkkkkkkk’s and lllllllll’s before I realize where I am. :smiley:

Hello.

I updated the gman script in post #20 It now uses the mandoc macro package that discovers any other.
I have also removed some error messages if there are any parsing errors of the man page for display by groff.

This makes gman unusably for debugging manpages, which is ironic, given the Debug title and all. :slight_smile:

Hello.

I have updated the script in post #20, to use a unique tmp file, for the case you load the manpages from qlmanage and into Safari, by clicking on a section link, and then makes Safari refresh a previously loaded page.

Also sends qlmanage to the background so you can continue working in the terminal window, while watching the manpage.

Enjoy!

Hello.

I have posted the very final version of gman in post #20. It now tells you that you have to check in another section of man pages, if you have specified a section, where the man page wasn’t found.