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
Add New Comment
Viewing 7 Comments
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
I have a script I've used for a while that uses PDF rendering of pages-- see http://www.atomicbird.com/blog/2007/07/man-page... to see how it works.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
should work as well and doesn't require gui scripting. Use "//apple_ref/doc/c_ref/" to show documentation for C code (e.g. Carbon functions and constants; cocoa class names work too).
Do you already have an account? Log in and claim this comment.
But you've just killed my blog post! ;-)
Do you already have an account? Log in and claim this comment.
So to open the "interesting" man page (1) (that's what your script does as well) you can use
tell application "Xcode" to show document with apple_ref "//apple_ref/c/func/strlen"
to open the man page for strlen. And
tell application "Xcode" to show document with apple_ref "//apple_ref/occ/instm/NSArray/initWithArray:copyItems:"
to show the documentation for -[NSArray initWithArray:copyItems:]. And so on. Semi-useful if you want to use a better editor than xed for code editing, but still look at XCode documentation from there (only semi-useful because you have to guess the top-level link like occ, c etc first before sending the applescript command to xcode).
Add New Comment