Re: HTML and Applescript?
Re: HTML and Applescript?
- Subject: Re: HTML and Applescript?
- From: has <email@hidden>
- Date: Sat, 6 Nov 2004 18:11:16 +0000
Vic Piercy wrote:
Anyone know if you can have Applescript create HTML. I would like to
have an applescript create an HTML page. Has anyone tried this?
Thank You!'
HTML is just text, so short answer is yes. Presumably what you're
really asking is 'Is there a fast, easy way to generate HTML
[documents] using existing tools?' to which the answer is... umm,
barely. AppleScript's native text-handling facilities are very weak
and its library support virtually non-existent, so you're very
limited:
- For generating arbitrary HTML from scratch, your options are either
to use Satimage's XMLLib osax/Late Night Software's XML Tools osax to
generate XHTML documents, or to write your own HMTL generator library
from scratch (which I don't really recommend as it's a fair amount of
work requiring good knowledge of HTML to implement, and it's
performance will fairly suck at the end of the day).
- For HTML templating, there's only one option I know of:
HTMLTemplate
<http://applemods.sourceforge.net/mods/Internet/HTMLTemplate.php>.
This compiles XHTML templates into simple AppleScript-based object
models. You write a second script containing AppleScript code to add
data to this object model, and attach it to the compiled template.
Your main script then loads the compiled template and sends it some
data, and rendered HTML is returned. There's various tools for
pre-compiling templates and auto-loading them from disk so it gives
decent performance and is pretty easy to use, and there's some
example projects included so you can see how it works.
Note that HTMLTemplate doesn't automatically HTML-encode data before
inserting it into the template, so you'll need to use a third-party
tool for that (preferably one that's Unicode-aware if you want to
encode non-ascii characters in addition to <>&"). I wouldn't bother
trying to do this using vanilla AppleScript - it's far too slow - and
I don't know if there's any osaxen that fit the bill, though there's
at least one freeware application, UnicodeChecker
<http://www.earthlingsoft.net>, that can do the job:
tell application "UnicodeChecker"
set htmlTxt to XHTML representation of txt with converting low ASCII
end tell
For serious work I'd still suggest looking towards other languages
such as Perl and Python where there's an absolute wealth of
third-party tools available and performance is much, much better. For
example, I've ported HTMLTemplate to Python
<http://freespace.virgin.net/hamish.sanderson/htmltemplate.html>
where it's at least ten times faster, simpler to use and also has
better documentation and tutorials. e.g. Here's a script that renders
the current iTunes playlist to HTML:
<http://freespace.virgin.net/hamish.sanderson/iac_examples/iTunes_albums_to_HTML.html>.
And there's a quite ridiculous number of alternative templating
systems available if that one doesn't float your boat, plus a number
of options for arbitrary HTML generation, build forms, etc.
HTH
has
--
http://freespace.virgin.net/hamish.sanderson/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden