\n

Thinking Home can be used with web server software two different ways. It can respond to AppleScripts launched by web server software or it can handle requests directly as the CGI application. This discussion explains the AppleScript CGI setup. It assumes you are already familiar with your web server software.

Using an AppleScript as part of the web server interface has the benefit that it can get the status of devices from Thinking Home and the html response can be formatted in a custom fashion.

On Mac OS X, Apache is the default web server and does not provide an AppleScript interface. The Thinking Home installer places a CGI module, ThinkingHomeCGILink, in the /Library/Webserver/CGI-Executables folder that enables Apache-style CGI requests to be sent to an AppleScript or directly to Thinking Home.

These steps assume you are using an Apache-style web server.

Step 1: Use Terminal to set up /etc/httpd/httpd.conf to use ThinkingHomeCGILink to handle .scpt files.

The new lines in httpd.conf should look like:

> # Files of a particular file extension
> AddHandler AppleScript .scpt
> Action AppleScript /cgi-bin/ThinkingHomeCGILinks

The web server will need to stop and start to make any changes take effect.

Confirm that ThinkingHomeCGILink is executable and can be run by the user owning the httpd process, normally user "www".

Step 2: Set the html form to use your AppleScript.

Set the html form to refer to your Thinking Home AppleScript as the intended CGI "application".

For example:

> <FORM action="http://123.456.789.4/cgi-bin/myapplescript.scpt" method="POST">

GET and POST work equally well.

The .scpt extension set in the httpd.conf file results in ThinkingHomeCGILink being run. At that time, ThinkingHomeCGILink will run your AppleScript and pass it any CGI parameters sent by the web browser. Your AppleScript can then interact with Thinking Home and do any other scripting. The result returned from the AppleScript is then passed back to the browser as a web page.

An example is provided in the Thinking Home folder.

Leave a Thinking Home document open in order to refer to devices by the given names. The document window also specifies the type of interface and serial port to be used. When no document is open, the settings from the Preferences are used and devices must be addressed by house and unit ID.

See also: Direct CGI