You asked...
The script has to be compiled as a "Stay-Open" application", which means that once it's launched it never quits. The same condition applied in OS9, so it wasn't too hard to figure out. A mention in the documentation would have been nice.
Applescript modules (called scripts) are not plain text files, but must be created by a special editor ("Script Editor.app" is one.) When the file is Saved, options allow the file to be saved as an application. This one file then functions as an application but also contains both source and object. When you launch the file, the application runs. If instead you opened the same file with the editor, you could edit the source and Save again.
Scripts typically are coded in a single file with a program at the top followed by all its subroutines. The top program is called the "run" handler because it is run whenever the application is launched.
Subroutines are called "handlers" because they can be accessed externally, from other scripts, even other processes. There is syntax to call a handler as a subroutine from the run handler or any other handler in the script. There is also syntax to call a handler defined in another application:
tell application "foo" to dowhatwith given params
You can even make the top-level program in another application run again:
tell application "foo" to run
The name of the handler and the syntax for its parameters would be defined in the other script:
source in file "foo":
<... run handler code here>
on dowhatwith given params
<..."dowhatwith" handler code goes here>
end dowhatwith
For these sample acgi applications, the run handler is null: when you launch them they do nothing. However, they all have (at least) one handler named "handle CGI request".
on handle CGI request
<...>
end handle CGI request
This is the entry point for Apache or MacHTTP or WebStar or whatever http server is calling the AppleScript cgi.
Apache will first launch the application then call the "handle CGI request" handler. Problem is, the application will finish its run handler and quit almost instantly, so then there's no process to handle the "handle CGI request".
The solution is to make the AppleScript "stay-open" when saved, so that once launched it never quits. And there they are in my dock right now, still running after my tests yesterday. I can quit them manually.
I like to code my cgi scripts so that they do quit by themselves after a few minutes with no work. This is assisted by a special "idle" handler which, if present in the script, MacOS will call with no parameters every now and then.
So I'm off and running on this path for now, to see where it leads.
Thank you very much, Anthony, for your help and encouragement, and especially for your review of some very attractive alternatives.
--Gil
12 inch PB G4 w/20 inch Flat Plane Array Mac OS X (10.4.9)