This script will let you take an action on each and every node in an outline. For this example I am bolding every headline, but you can use if-else statements or what-have-you where I have defined the
actionHere () function.
I use Dave Winer's "count headlines" script at the beginning to determine how many headlines there are. Then I use a for loop to (a) perform an action; and (b) move to the next headline in the outline.
The last time the for loop runs is at the penultimate headline, which brings us to the last headline. If the loop ran any longer, the script would freeze. So I repeat the action on the final headline, and I'm done.