Hi,
Does Applescript have a class construct mirroring the class construct
in VBA?
AppleScript doesn't include a class type - instead it supports a form
of prototype-based OOP using its 'script' type. (Script objects can
also also used as modules, although AppleScript's built-in support for
module management is sorely lacking.)
Simple example:
on makeFoo(x)
script Foo
property y : 2
on bar(z)
return x + y + z
end bar
end script
end makeFoo
set f to makeFoo(30)
f's bar(10)
--> 42
(Note: you can also use AppleScript's built-in 'copy' command to clone
existing objects, but this has technical problems so should almost
always be avoided. Stick with constructor functions as shown above;
they work just fine.)
The AppleScript Language Guide has a chapter on script objects; it
doesn't really explain how to use them effectively, but if you already
know OOP you should be able to figure it out. (This is what I did.) Or
you could take a look at various AppleScript books and see if any of
those has a halfway decent discussion of the subject; Matt Neuburg's
'AppleScript: The Definitive Guide' might be your best bet as it's the
most technical-oriented one.
You could also check out the libraries at AppleMods (http://
applemods.sourceforge.net/) which I wrote a few years back. Several of
them provide examples of AppleScript OOP (the Types library is a good
simple one to start with).
....
Alternatively, if you'd rather stick with more familiar class-based
OOP, you might consider using Python or Ruby instead of AppleScript -
see my sig for links to suitable Apple event bridges.
The only caveat is that their OSA support - needed to attach scripts
to attachable applications (System Events' folder actions, Mail's rule
actions, iCal's alarms, etc.) - is currently a bit lacking, although
that's being worked on (see
http://appscript.sourceforge.net/pyosa.html
for an unfinished but mostly usable Python component).
Also, here's a link to a recent article on rb-appscript that includes
an example of scripting Excel with it:
http://www.oreillynet.com/pub/a/mac/2007/02/27/replacing-applescript-with-ruby.html
HTH
has