Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Use AppleScripts to generate web pages' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use AppleScripts to generate web pages
Authored by: neptune on Dec 22, '03 11:14:58PM

I'm not sure what you wanted to generate using the Applescript, but I have been using Applescript to generate both html and hdml web pages for several years. I have created scripts with using the following format:
On idle
-- put code here
return 60 -- sets return rate to every 60 seconds
End idle

The script is compiled as an application with the "stay open" button checked in the Save dialog box. Hint: use "on run" to debug your script, then change to "on idle" at the end.

Whatever code is included will run repeatedly every 60 seconds. Of course you can set the rerun period to any number of seconds. The script creates a web page using the "write" command to a fileref number. Since the same file is continuously being overwritten with new values, times, or data, that new data is served to the outside whenever that page is called for by a web browser and appears as if it were created on the fly.

We use this technique for monitoring tanks that house thousands of fish - generally endangered species. The Applescript wakes up once a minute, talks to an special application specific to the data acquisition and control hardware that is actually talking to the sensors, and reformats those measurements into an hdml page. HDML is the markup language used in web enabled cell phones and is very similar to HTML, but the syntax is less forgiving of errors. The fisheries system operators can use their cell phones to view the status of pumps and heaters, as well as see temperature, pH, dissolved oxygen, pressures and flow rates, with the measurements no older than 60 seconds.

The on idle technique is easy to write and does not expose scripts to external hacking. Applescript could be used in this manner to create a web page with the current time, date, weather info, stock prices, etc.



[ Reply to This | # ]
Use AppleScripts to generate web pages
Authored by: Graff on Dec 23, '03 12:14:29AM
On idle
-- put code here
return 60 -- sets return rate to every 60 seconds
End idle

The script is compiled as an application with the "stay open" button checked in the Save dialog box. Hint: use "on run" to debug your script, then change to "on idle" at the end.

Right, and remember that you can have both "on run" and "on idle" handlers in your script, along with other handlers that do other sorts of stuff.

The "on run" handler does stuff as soon as the script application is run. If you don't save the script as a stay-open application then it will quit once the "on run" handler is done. Even if you have an idle handler in your program you probably would still have a run handler to do setup sort of stuff.

The "on idle" handler is for performing tasks occasionally in a stay-open script application. It is good for monitoring, performing stuff in the background, idling until the script is re-activated by another program, etc.

There is also an "on quit" handler which traps the normal quitting of the script application and does some cleanup before quitting. Since a quit event will interrupt any other processing going on in the script application this is important. When you are done cleaning up a "continue quit" statement in the "on quit" handler will cause the application to end.

You can also define your own handlers which are basically functions. For example, a "DrawPage" handler which draws the web page when called by your run or idle handler. These handlers can be called by other scripts and programs.



[ Reply to This | # ]