toxicsoftware.com

RANDOMIZE USR 0

toxicsoftware.com header image 2

View man pages in Xcode script

July 28th, 2007 · Comments · Default

I really ought to start blogging again..

So here’s a quick and simple shell script to open Man pages in Xcode. I’ve been using the very nice “manopen” utility to view man pages in a GUI application. But that tool is having difficulties with a certain new big cat. So I was looking for a replacement tool but it turns out Xcode has a very nice Man page viewer built in. With the aid of a little shell/Applescript hybrid scripting I can now open Man pages in Xcode from the command line. This little tool isn’t fool proof but in a pinch can replace manopen and also bwana.

This script should work on 10.4 with Xcode 2.4 (and maybe even older versions of Xcode). Because the script uses “System Events” to drive the GUI you will need “Enable Access for assistive devices” turned on within your Universal Access system preference. To install just copy and paste the script into a file, make the script file executable and make sure it is in your PATH (I keep my scripts in ~/bin). I call the script “manoxcode” (so that bash autocompletion and muscle memory continue to work together).

#!/bin/sh
# manoxcode
# Real simple tool to show man pages in xcode. Uses UI Scripting so "Enable Access for assistive devices" needs to be on.
osascript - "$1" << EOF
-- Inline AppleScript starts here...
on run argv
    tell application "Xcode" to activate
    tell application "System Events"
        tell process "Xcode"
            click menu item "Open man page..." of menu 1 of menu bar item "Help" of menu bar 1
            tell window "Open Manual Page"
                set value of text field 1 to item 1 of argv
                click button "OK"
            end tell
        end tell
    end tell
end run
-- Inline Applescript ends here. Keep the EOF text in place!
EOF

Tags:

Viewing 7 Comments

blog comments powered by Disqus