Script Objects/Libraries/Code Reuse
Script Objects/Libraries/Code Reuse
- Subject: Script Objects/Libraries/Code Reuse
- From: Richard 23 <email@hidden>
- Date: Sun, 4 Feb 2001 16:17:26 -0800
I know what you're thinking. "Oh no, another long-winded rant."
Well, fine. Be that way! But I'll go ahead anyway...
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Mini-Rant on a design which overlooks importance of code reusability
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
It took me much longer than it should have but I managed to hack
together a method for making externally loaded library files globally
visible, therefore intuitively usable, without hardcoding the path to
the library file in the script (which seems kinda stupid to me) or
targeting tells at a script property (which also strikes me as silly).
The point of a library is that it contains routines and properties
which on occasion get updated. When written and called properly,
changes to the library routines do not break scripts using older
versions, so discovery of the file should occur at runtime, or at
least compile time (where the current version is acceptable but would
benefit from a future version) and should not require updating of every
script which uses one.
Scripts utilizing the common (but unfortunately necessary) copy and
paste of core routines suffer the indigity of not being updated when
the copied routine has been updated elsewhere but use of library files
is not standard and straightforward, and including multiple script
resources in a file is undocumented and something which I haven't
gotten to work reliably yet.
Then there's the suggestion to remove comments from scripts which have
gotten too big to compile, advice which I patently loathe. Yeah, great
solution!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Long-term impact upon AS by not providing practial library method...
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
AppleScript's user base is probably less than it would (or should) be
if libraries were as easy to incorporate as in languages such as Perl
or JavaScript.
Although most of the libraries for JavaScript tend to be yet another
mouse rollover image swap method...take a look at <
http://www.cpan.org>
to see what a user base is capable of when the language makes itself
easily extendible through code reuse. Amazing quantity of scripts for
everything under the sun.
Is all that we see or seem, but a dream within a dream?
The theory that loading scripts into separate contexts is a clever
means of not cluttering up the global namespace...that just doesn't
wash. If this were the case then why the osax implementation which
steps all over the global namespace in an all or nothing fashion.
It's easy to pollute the namespace via osax. Why can't I easily
practice cluttering my own namespace within my own script? Phooey!
If JavaScript for OSA were just a little prettier and little more mac
friendly I'd almost consider doing more Apple scripting with that.
The object model and library usage is so much simpler and more
straightforward.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Sure, R23, complaints are neat, but what else can you contribute?
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
I can offer up a working script which shows a possible method to make
library usage a little more realistic. I approached the problem by
turning the object model on its head, making the most deeply nested
child the parent, so through the eyes of a child the script is able
to see the entirety of the script without complex statements built
with "tell" and "its". The effect of this object-model shakedown is
that even externally loaded handlers don't need fully qualified
tells (no tell required whatsoever, even when assigning an
application as the parent).
If anyone is interested in seeing how I did it or what I'm babbling
about, I will provide a link to an html formatted and semi-documented
online copy of the script and a download link a little later on.
Even if nobody wants to see it, I'll probably post a link anyway...
If someone has no life and is dying to see it but I have not posted
a link, send me an offlist email to get me to wrap it up as I'll
probably have moved on to somthing else for awhile. I've already
burned out on this particular script! It took too long to hammer out!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
An vague description of an abstract concept in the monologue format
is interesting and all (zzz) but what does it do? Will I use it?
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Oh what does it do? Oops! Almost forgot to include this minor detail.
It extends the "Execute Selected Script" script that comes with
"Tex-Edit Plus" by running either the selection or entire window as a
script object. If an error is generated by the attempt to run it in
AppleScript, other OSA Languages (such as JavaScript for OSA) are tried
before giving up the ghost. It also implements a result window as a
script object, vaguely resembling that found in Script Editor, which
includes showing the result (yes, even records) in styled text.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Why did you do such a thing? Are you some kind of nut?
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
I did this because when doing text processing with AS it sometimes gets
tiresome switching between applications for minor code tweeks...
Needing a mini environment to experiment in, I threw this together.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
I bet it uses all sorts of neat osaxen! What do I need to use it?
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Paraphrasing Blazing Saddles, "We don't need no stinking osax."
Although it does use an updated (unreleased) version of CoerceToString
which uses the upside down inheritance method I've been working on.
The script itself resides in the script menu for Tex-Edit Plus (I
assigned it the cmd-R shortcut key by appending /R to the filename)
and the CoerceToString library resides in a "Script Library" folder
within Tex-Edit Plus. If already located elsewhere an alias can be
placed in this folder instead.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Wrap it up so I can get back to reruns of M*A*S*H and folding and
sorting newspapers like I do every sunday for kicks.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
I hope that unless Apple plans on letting AS die like what seems to have
happened to hypercard... they will finally untie the hands of AppleScript
by making code reusability a reality for non-contortionists.
And for God's sake, update Script Editor for the new millenium.
We want 48k or 64k or 128k. 32k is not enough which is what a
responsible scripter must conform to for distributing to a wide
audience. Don't tell me about Smile and Script Debugger.
I already know. I already have them. Thank you.
R23