This is a script that helps you locate and view a C-header file, the syntax is gheader stdio, and not gheader stdio.h, it is meant to work with Apple’s headers, the standard C-library, and what libraries you have downloaded via Macports. (/opt/local/include). You’ll get the hang of how to modify it, should you need it.
The shell script, should easily be incorporated into an applescript, and leverages upon the searchpaths I have (you specify ) specified. Also the fact that the include file with the shortest path is the most correct one. So if you need a different searchpath, then you’ll have to add some if clauses. It is also quite silent if you execute it from an applescript, only echoing the path of the header file if you are in a terminal window.
if [ $# -eq 0 ]; then
if test -t 0 ; then
echo “gheader: You need to supply a name that resembles a header file as a parameter.” >/dev/tty
fi
exit 1;
fi
toopen=0
if [ $1 = -o ] ; then
toopen=1
shift
fi
if [ $# -eq 0 ]; then
if test -t 0 ; then
echo “gheader: You need to supply a name that resembles a header file as a parameter.” >/dev/tty
fi
exit 1;
fi
header=${1%%.h}.h
a=$(locate $header |grep "^/System/Library/./$header" |awk ‘{ print length $1 }’ |sort |sed -n '1s/([[:digit:][[:digit:]])([^[:digit:]][^[:digit:]])/\2/p’)
if test -z $a ; then
a=$(locate $1 |grep "^/usr/include/./$header" |awk ‘{ print length $1 }’ |sort |sed -n '1s/([[:digit:][[:digit:]])([^[:digit:]][^[:digit:]])/\2/p’)
if test -z $a ; then
a=$(locate $1 |grep "^/opt/local/include/./$header" |awk ‘{ print length $1 }’ |sort |sed -n '1s/([[:digit:][[:digit:]])([^[:digit:]][^[:digit:]]*)/\2/p’)
if test -z $a ; then
if test -t 0 ; then
echo “gheader: Couldn’t locate $header” >/dev/tty
fi
exit 1
fi
fi
fi
if test -t 0 ; then
echo $a >/dev/tty
fi
if [ $toopen -eq 0 ]; then
qlmanage -px $a 2>&1 >/dev/null &
else
open $a &
fi
exit 0[/code]
I have changed the script in post #1 to provide a better form of agnosticisim.
Trouble was, with the previous scheme, that .so files and what not, ended up with an icon in quicklook, so I have inverted it all, looking strictly for header files, and adding any missing .h suffixes for starters instead of ignoring them during the lookups.
I have updated the script in post #1, to be sure that the latest version is there, I have renamed it to ghead for brevity.
I call it with the script below, to have the header files I want to have a peek at handy, from a history list. This concept isn’t fully evolved yet, one day I care, and have the time, I’ll synchronize this history with some other scripts I use from Safari, Preview and XCode, to have one common history list file.
I thought: “why not coalesce all the scripts into one, then I don’t have to write handlers for writing the history for each and every script that uses ghead in post #1”. The script in the post above, is a “one size fits all”, that is to be used from every app, with and without a selection. You have to see to that nothing is selected in order to get the dialog box, but it respects the previous contents of the clip board.
I have also fixed an issue whith Safari, when it gets to be obnoxious, and don’t let me copy the selection of the front window.
I saved it as an applet, with the name ghead, and set LSUIElements to 1 in its plist file to make it work from spotlight, and quicksilver flawlessly as well.
And as far as I know, I am done with it. I won’t write help file for this, so the basic idea is to mark or input the name of a header file, say stdio.h, or CFSet.h or something, and it will pop up in quicklook right in front of you. If XCode is still the default editor for c and h files, then the header file will pop up into XCode if you double click on it.
I must say I am fairly happy with the applet for displaying header files, so I thought I’d wrap the gman script: A shell script for using quicklook to display manual pages into the same kind of applet. Here it is
You make a service for it to execute the applet from the contextual menu the same way as described in post #8.
If the manual page looks like it is html formatted, then chances are big that the manual page will pop up in Safari or your default web-browser, should you double click on it in quicklook.
I have done something more to the logic of ghead, so that it won’t be baffled by a selection in your active window, that doesn’t return a result.
I have also tried to speed it a little bit up, but I realize I have to write the history to disk, to get it to be more responsive, and it isn’t that bad really. But who knows, those computer seconds do take a long long time.
PS. People who use this are also supposed to have activity monitor open. But now it dies after 2 minutes of inactivity, should the dialog of the faceless app disappear, without you being inclined to hide the frontmost apps to find it.
Due to the changes I have made, I don’t think that to be an issue anymore anyway.
A little script that shows the folders of a directory tree that contains scpt, applescript or scpt files, in a TextEdit window, then it asks you, and lets you open one of the folders if you want to.
It doesn’t play well with filenames that contains “.” (ellipsis) and such.
If you have your script folders in just one place, it would be practical, to subsitute a hard path, for the choose folder dialog it starts with.
Here is one, you’ll like if you need to look at your own header files from within XCode, you just change the property revalInTextEdit to false, if you think an open dialog will suffice. You just change the script to use a posix path, if you have your stuff in one place, and customize it further, if you want to get at your locall library source files.
I have improved the three scripts in post #17 slightly with regards to search criteria, so that no double ticks, ment to escape the regexp are showing up in the dialog again.
I have updated the scripts in post #14,#15#16 and #17 Mostly with regard to layout, and made it easy to duplicate the script in post #17 to suit your own needs for other dedicated paths, as you usually know which framework, your are looking for an identifier in. (That is why I haven’t made it into one slough with a choose from list for picking framework.