Dunno if this is remotely relevant, but since OS X (and
OPENSTEP before it) has some notion of "services" built into it, I
thought an article explaining how it works in that environment
might be useful:
http://www.stepwise.com/Articles/Technical/Services.html
Interestingly, one of the specific services available for
OPENSTEP (which I assume could work for OS X as well) is
something called "TickleServices." In the words of the article
author:
This program allows anyone to turn a TCL script into an
OPENSTEP service. The author, Scott Hess, provides quite a few
utilities and literally hundreds of example services that you can
try out. Anyone who wishes to try out the power of services
should try this program out. Developers who want a really easy
way to create services should also examine this program, since
the documentation is very good.