More Automator

I worked a little more with automator (when I should have been studying regression analysis)… and have come up with a cool new automator. This incorporates an undocumented aspect of automator, so it took some trial and error to figure out. Basically, I wanted something that would allow me to turn a request to view a man page into a pdf file for easy printing and viewing in the gui side of Mac OS X. Only a unix geek could love the man page as it is… for unix newbies though, it can be quite frustrating. Personally, I am use to man pages, but I still like to print some out now and then and converting them to pdf allows me to access them without opening terminal (not that you wouldn’t probably have terminal open anyway).

So I wanted to find a way to make a man page into a pdf. Of course you can do this from the terminal, but where’s the fun in that (plus you have to remember the commands each time you want to do this). There is a free GUI utility called ManOpener that allows you to view man pages easily as well, and is much more featured than this automator tool. But if all you want (as I did) was a man page made into a pdf, then this is what you need to do;

  1. Open Automator, from the Library column select TextEdit. From the actions drag “Ask for Text” over to the workflow area.
    • In the question field type “Enter man page name?” or something to indicate what you need to enter
    • You can leave the default field empty or enter something that will serve as a reminder of what to enter
    • Check the require answer box
  2. Next, from the Library column select Automator, then from the actions drag over the “Run Shell Script” to the workflow after the previous item. Type or copy & paste the following as one line, modifying the paths so that they point to your preferred locations (include the quote marks this time);

    man -t $@ > /hardrive/Users/Shared/manpages/$@.ps | echo -n “harddrive:Users:Shared:manpages:”$@”.ps”

    Set the “Pass Input” to “as arguments”

    Note: The $@ takes the value entered in the “Ask for Text” and runs it as a shell command. The first part which calls the man page then passes it to a postscript file named with the name of the man you are looking for, then it echoes out the path to the next function. The echoed path has to be in the style of the Mac OS drive path reference which uses “:” instead of slashes “/”.

  3. Last select Finder from the Library column and drag “Open Finder Items” to the workflow in the last place. Set the “open with” field to the Preview application. The path passed from the previous action will be opened in Preview converting it into a pdf.

You are ready to test, click the run arrow and try it out. If everything works, the requested man page will be open in Preview at this point. You can either save it or discard it after use. You can get fancy and do things like check for existing ps files or remove the ps file after it is converted. But this gives you the idea of what fun you can have with automator and how it can make working with unix fun. Be sure to save your workflow and make it readily accessible on your dock or wherever you like to put things to be accessed often.

Comments are closed.