I have been trying to figure out how to run an AppleScript to generate a web page for a long time. I tried using Perl and PHP, but always got an error message because the script was running as a different user than who was logged in at the time. Changing the Apache setup to run as a different user does not solve this problem. But you can make it work by using Server Side Includes (SSI). If you set up Apache to run as the user that is logged into the system, you can run AppleScripts inside your webpages by using SSI and the osascript program. The first thing to do is to set up Apache to run as the user that is normally logged into the system. Since I am usually the only one logged into my computer, I have Apache run as me. You need to edit (with root privileges) the /etc/httpd/httpd.conf file. Find the line that says:
User wwwand change it to
User myNameReplace myName with the short name of the logged in user. Then you need to enable server side includes in the same file. Uncomment these two lines:
#Addtype test/html .shtml #AddHandler server-parsed .shtmland then restart the webserver (sudo apachectl graceful, or via the Sharing preferences panel). You should now be able to use Applescripts inside your webpages. You can do this by using:
<!--#exec cmd="/usr/bin/osascript MYAPPLESCRIPTNAME"-->
You can either replace MYAPPLESCRIPTNAME with a file, or with the script written out. I use this with some other programs to control my EyeTV program from the web. Also, you can use this to view your iCal calendars over the web or view the current track in iTunes.
Mac OS X Hints
http://hints.macworld.com/article.php?story=20031213233020700