So you’re writing this email explaining to a customer or colleague on how to do some really cool thing (say hide a file in the Finder) in Terminal. The command for that is
chflags, but of course you can’t remember the exact syntax. So you open Terminal and write
man chflags and find the correct options.
However reading longer man pages (try
bash) in the Terminal can be kind of painful. I’m sure some of you have encountered this command before:
man -t chflags | open -f -a "Preview"
which uses the
-t flag to pass the output to
groff and generate a postscript file which we then pipe into the Preview app, using
-f option to pipe the stdin into a file to
open in a GUI app. Preview will then convert the postscript to PDF and display the result.
I think this started to work in Tiger and you should immediately go and add this command to your shell’s
profile. Which is nice but you still have to make the roundtrip to the Terminal.
Enter Snow Leopard Automator Services. Open Automator. Create a new service. Leave the settings to work on ‘text’ in ‘any application’. Search for the ‘Run Shell Script’ action and double click to add to the workflow. Leave the Shell at ‘/bin/bash’ but set the ‘Pass Input’ option to ‘as arguments.’
Replace the default code with
man -t "$1" | open -f -a /Applications/Preview.app
Save the Service and give it a nice name, such as “Open Man Page.”
Then in any application you can ctrl/right/double-finger click on a word and “Open Man Page” will be an option in the menu. You can even go to System Preferences -> Keyboard -> and add a keyboard shortcut to the command. If any other command in the man page strikes your curiosity, just ctrl/right/double-finger click the word in Preview and select “Open Man Page” again.
Another rarely known but quite useful trick is that you can create hyperlinks to man pages with the
x-man-page://command URL. This will open the man page in
man in a new Terminal window. This is especially useful in IM sessions.