When Apple based OS X on a BSD kernel,
they sought a way to combine the power of GUI scripting with the
power of shell languages like Perl, bash, Python, and more. The
result was osascript, a simple shell utility that could run
AppleScript from the command line.
That was fine and dandy for interactive or timed usage, but it
didn't immediately lend itself to using AppleScript
as a CGI through the Apache web server. ACGI Dispatcher from James Sentman,
on the other hand, gives that ability quickly, simply, and cheaply.
ACGI Dispatcher costs anywhere from $15 to $90, depending on your
needs, and a 30-day trial download is available for testing.
Installation is simple: extract, drag the dispatcher to your
/Library/WebServer/CGI-Executables directory,
and double-click to finish the installation. You'll
be asked for your administrator password so that the following lines
can be added to your
/etc/httpd/httpd.conf file:
#BEGIN acgi dispatcher
Include /Library/WebServer/CGI-Executables/dispatcher.app/Contents/acgi.conf
#END acgi dispatcher
After those lines have been added by the dispatcher program, stop and
restart Apache via your Sharing system preference (alternatively, use
sudo apachectl restart from the shell). Once the
web server has restarted, and with the dispatcher running in the
background, you'll be all set to serve
AppleScript-based CGI. Thankfully, you can test your new ability with
the included itunes.acgi.
To control
iTunes through a web browser,
simply drag itunes.acgi into
/Library/WebServer/CGI-Executables, make sure
the dispatcher is running, and load
http://127.0.0.1/cgi-bin/itunes.acgi. Assuming
that iTunes is running at the time of your request,
you'll see a screen similar to Figure 1.
Figure 1. iTunes control via web browser
As the screenshot suggests, you have access to any playlists
you've previously created (smart lists or
otherwise), as well as the standard playback controls. The benefits
of having one computer serving itunes.acgi,
while you change the track from another computer or handheld in
another room, are nicer than you'd think. Full
source for itunes.acgi is provided so that you
can modify the output of the page or learn how to create your own
AppleScript CGIs.
If you're planning on using ACGI Dispatcher in a
production environment, you'll want to make sure to
register the software (after 30 days, it'll start
displaying expiration warnings on the bottom of your results) and
include the dispatcher as part of your Startup Items. Apache
can't start the dispatcher automatically, so
ensuring that it loads at login is important.