R23's Osaxen Rant (or much too much ado about nihil)
R23's Osaxen Rant (or much too much ado about nihil)
- Subject: R23's Osaxen Rant (or much too much ado about nihil)
- From: Richard 23 <email@hidden>
- Date: Thu, 25 Jan 2001 06:41:28 -0800
The mention of Akua in a question regarding finding the screen's
bounds got me going on the following tirade.
This is based on a mixture of knowlege and experience... but
is mostly fueled by personal opinion (aka hot air).
If you have read my rants before you probably have a good
idea whether you should read on or just keep scrolling...!
If you're not into techie discussions of what goes on beneath
the friendly user interface then the page down key will be
your best friend.
To the "lurkers" and "newbies" out there I would just like to
preface this by saying not to take my word or anybody else's
as the "truth." If any of this interests or concerns you then
you should do a little research on your own to get the straight
dope.
This got much longer than I intended yet is barely the tip of
the iceberg. Perhaps I'll babble on at greater length on my
site at some point where I won't be bothering thousands of people
all at once. There I can annoy on a more personal level! 8)
Once again I apologize to everyone in the world for this post,
but after reflecting and deciding not to send it I realized it
had already been sent. Too bad, too. I wanted to apologize to
everyone in the world before it went out. 8)
- - - - - - - - - - - - - - - - - - - - - - -
Content Summary:
<r23 mode="rant" type="propellorhead">
akua vs finder terms: Akua Resource Sweets V1.14)
general osax "use or abuse" editorial
</r23>
If you're still with me, then, let's get on with the story...
- - - - - - - - - - - - - - - - - - - - - - -
Does Akua provide unique must-have tools which extend AppleScript's
reach and productivity or does it instead repackage already existing
functionality, rename existing standard terms, add terms which have
no effect other than to flag as reserved and pretty format certain
terms for display...establishing itself as a big fat namespace
polluter? (How's that for a loaded question?) I don't really know
so thought I'd do some snooping. At the close of this novel I'm
still unsure. (Didn't mean to blow the ending...)
One thing I am convinced of is that Apple did a pretty good job on
the osax implementation. The proof is in the fact that it works
in spite of what appear to be a number of conflicts just below the
surface.
- - - - - - - - - - - - - - - - - - - - - - -
I recommend those interested read the "About the OSAX Mechanism"
in the AppleScript 1.3.4 SDK.
ftp://ftp.apple.com/developer/Development_Kits/AppleScript/Documentation/OS
AX/Scripting Additions Mechanism
What stands out is:
Apple recommends that you use care when you decide to write a
scripting addition, as there are severe limitations to what you
can do in the context of a scripting addition, and the system
costs of managing large numbers of scripting additions are high.
and
Scripting additions are best suited for a small number of
unusual events, or setting or retrieving a small number of values.
If your task involves a large number of events or values, you
may consider creating a faceless background application to
accomplish the same task.
- - - - - - - - - - - - - - - - - - - - - - -
The aete* in Akua Sweets 1.4.1 weighs in at a hefty 109k.
* called "application dictionary" by AppleScript, but kindly
obfuscated by Akua, compiling as "Apple Event Term Raw"
the aete maps raw Apple Event codes to human readable
keywords which appear in your script editor.
For comparison, core AppleScript's terms are 31k (much of it contains
terms not implemented in AppleScript, provided as a guide to encourage
consistency among developers).
The often maligned Finder, workhorse of many a script comes in at 42k.
But it's not the size that matters...it's what you can do with it.
Resource tools (implemented in the Mac Toolbox but not directly
available to scripts) are money in the bank baby, roughly translated:
a useful addition to the propellorhead paintbox. Always on the lookout
for a better interface to these existing tools, my first stop was the
in Akua Resource Sweets V1.14.
I only peeked at the suite, made some quick comparisons to the
Finder and compiled a couple of scripts with Akua and Finder terms.
- - - - - - - - - - - - - - - - - - - - - - -
SWEET OR SOUR? Syntactic Sugar or Pure Lemon?
The first thing I noticed was that Akua replicates but does not
mirror the Finder's type names for icons. I would hope that where
the terms diverge, at least the underlying codes* match. [they do]
* 4 character codes identifying standard Mac data types
also familiar to ResEdit users.
Probably harmless but Both Akua and the Finder define 'ifam':
Finder: "icon family" (displayed this way in a Finder tell)
Akua: "Icon Family" (compiles like this outside tell)
odd precedence: Finder term gets precedence for
'icon family', while 'icl8' prefers the Akua term.
Both Akua and the Finder add terminology for the 'icl8' resource.
Finder: "large 8 bit icon"
Akua: "large eight bit icon"
Gee, this is fun! Akua overrides the Finder's term but
doesn't recognize it outside the tell block.
So finder's "8 bit" compiles to "eight bit"
but "8 bit" anywhere else gets an error.
Akua overrides the Finder term so even in a tell block the Akua
term is used. The only problem I would expect is if a script is
saved as text using the Akua term and recompliled later on a
system without without Akua.
A compiled script will be translated without a hitch. Any terms
not directed at the Finder would decompile to the raw event form.
- - - - - - - - - - - - - - - - - - - - - - -
British or American? (neither can spel ANEEway)
- - - - - - - - - - - - - - - - - - - - - - -
Akua puts a pretty face on the 'cicn' (color icon) resource.
displaying the raw code <<class cicn>> as "colour icon"
Yet the class right next to it defines the 'il32' resource
using a different spelling! C'mon, pick just one!
Finder: "large 32 bit icon" -- Any Colour You Like
Akua: "large color icon"
It has no equivalent for the icon masks.
Oops. Strike that. It does.
Presenting a new abstaction layer in confusovision:
Finder: "small 8 bit mask"
Akua: "small eight bit icon"
Finder: "small monochrome icon and mask"
Akua: "small one bit icon"
It adds terms for the mini icon (used in Standard File dialogs)
rarely used anyway and already accessible via the raw code.
Synopsis: Confusion Abounds! Value Added is Unclear.
The other icon types (the renamed Finder classes) probably are
only of interest to geeks and hackers who aren't afraid of codes
and shun all the extra typing required for the longer form.
Akua doesn't get the various icon types (only the 'icns') nor
does it extract the atomic icons from to composite icon suite
so why they exist at all is an open question.
- - - - - - - - - - - - - - - - - - - - - - -
Sorry about the length. I'm all classed out.
I'll touch on a couple of events and wrap it up.
- - - - - - - - - - - - - - - - - - - - - - -
Every defined term increases the number of symbols maintained
by AppleScript and these are global, man! Although junk food
is cheap, there is no free lunch...
- - - - - - - - - - - - - - - - - - - - - - -
the main event (no, Cal, not Main Event, it's just a section title)
- - - - - - - - - - - - - - - - - - - - - - -
The Finder can get an item's icon. When it does it returns the
entire icon family (small and large icons with masks as a record).
[the* icon for]
Akua's "the* icon for" sounds similiar but it's a slight variant.
* "the" isn't really recommended for use in event names
eg, "get the the icon for" but I'll try to hold back.
Akua gets the 'icns' (icon suite resource), a modern variation of
the System 7 icon family but does not seem to provide a method to
get the more compatible icon family. That's fine. Finder's here.
[save resource] NEWBIES BEWARE!
Testing its save resource command I found that if you do not
provide the optional target file, the resource is written to the
system file. When would this dangerous default be desirable?
The default file type for a new file is an Akua prefs file. Huh?
The reason for using save resource evaporated when "set the custom
icon of" event generated an "unimplemented event" error.
- - - - - - - - - - - - - - - - - - - - - - -
It seems like I've barely scratched the surface. A couple of items
in one suite of fourteen! Who knows how many redundant terms are in
there, how many of its events just replicate existing functionality
(and doom your script to dependency which may be totally unnecessary),
and how many existing terms it modifies such that a vanilla file saved
as text will not compile without Akua...
I better yank this thing out before I open a script that uses a raw
code that it redefines making my script die when run without it.
Or maybe I looked at the runt of the litter and missed all the
good stuff that would leave me cheering. I don't know yet.
- - - - - - - - - - - - - - - - - - - - - - -
This is just *opinion* here but it seems like using osaxen which
globally redefine existing terminology or repackage existing
functionality without adding value is probably playing with fire,
and certainly results in scripts which are not portable.
Stay home scripts don't mind this risk, but distributed scripts
are less likely to function as expected. I doubt many potential
endusers will bother with a script which doesn't work the first
time. Most people do not read the documentation either.
Just the global availability of 3rd party terms in itself increases
the likelihood that while some terms will be used on purpose, others
may seem natural (the script compiles) and become part of your core
scripting vocabulary. You begin to forget which terms are part of
AppleScript and which are from the myraid of 3rd party tools.
I've done it myself. It's only natural.
Before you know it, due to shifts in your scripting style, you'll
find that most of your scripts will become tied to the various
osax files, unable to work without them. Master becomes servant.
Sounds like the "slippery slope theory" or "symbiotic stew."
Yep, all out of cliches.
If portability is important to you, I'd suggest you somehow keep
track of the source of the proprietary terms you use. Nearly an
impossible task as they look exactly the same as the standard ones.
In addition to the 146 events and 77 classes and a handful of
enumerations (constants) that you can see, it also contains 75
coercion handlers* which you cannot. As visible as the wind and
sometimes just as powerful.
* coercion handlers perform automatic data conversions as
needed invisibly. A text to fss (filespec) coercion makes
this possible (without the coercion an error occurs):
set filePath to "disk:folder:file"
info for filePath
what's really happening is one of these:
info for [file] filePath
info for ([file] filePath [as file specification])
info for [alias] filePath
info for (filePath [as alias])
Sure they're convenient, but how do you tell what parts of your
script are portable and which are not? Coercions leave no trail.
I got bitten distributing a project dependent on coercion handlers
in Jon's Commands which has only 3. I didn't know anything about
coercion handlers then. I have since become a little more familiar!
Going back over my scripts and removing the dependancies wasn't too
bad but I can't even be sure if I got them all.
I know they are meant to be useful but the effect of 3rd party global
terms can be similar (in my view) to a virus spreading through your
scripts even if you don't realize you're using them.
If you ever need to remove the osax or if it breaks down the road
you'll certainly get a harsh dose of reality! We don't want that.
- - - - - - - - - - - - - - - - - - - - - - -
The Cold Turkey Challenge (oooh, that smarts!)
- - - - - - - - - - - - - - - - - - - - - - -
Try something like Akua for a month and then remove it (or if you
already use it then remove it now) and see in a worst-case scenario
how many of your scripts no longer work, and of those how many could
be rewritten with existing terminology. Just for fun! See how many
you can figure out from the raw codes alone. (it can happen if you
toss an addition you didn't realize you were using.)
- - - - - - - - - - - - - - - - - - - - - - -
What? A possible solution? Maybe.
- - - - - - - - - - - - - - - - - - - - - - -
If I ever find the need to use Akua, the first thing I'll do is
use Applet Binder to create an applet using Akua's osax file.
This adds the requirement that the addition terms would only be
available within a tell block (or statement) targeted at the
applet. This also localizes the coercion handlers.
No more surprises.
That way at least I can tell the difference between Akua enhanced
(or dependent, depends on how you look at it) and portable scripts.
You will never find it in my Scripting Additions folder.
You can look into this approach here:
<
http://www.magma.ca/~awolsp/>
I may extend Applet Binder's minimal documentation on my site.
It's very brief and it's not exactly a beginner's tool.
I won't editorialize (much) about how I think misuse or overuse
of osaxen encourages laziness and discourages scripters from
having faith in their own abilities. One would logically assume
that an osax will be faster anyway, but it is often not the case.
Going for an osax first robs you of the knowledge acquired through
experience and results in a script which is not portable.
Seems like a double negative.
However there are many valuable tools added by osax files which are
beyond the ability of AppleScript and in those cases of course go with
the osax. I'm not suggesting we all shun lightbulbs and use candles!
While I mention Akua, the same applies to osaxen in general.
Singling Akua out for a public flogging isn't completely fair so I
would like to make the point that while the specifics vary, the same
types of issues are possible in any osax file. And between you and
me, I think Akua would make a fine helper app, but an osax? Too big.
- - - - - - - - - - - - - - - - - - - - - - -
Advice to newbies
- - - - - - - - - - - - - - - - - - - - - - -
"People swear by them."
"There's so many cool features to add."
"I want them all!"
None of this really impacts you if you don't plan
on sending your better mousetrap out into the world.
The global nature of Scripting Additions can be your best friend
but it can also be your worst nightmare.
The individual scripter determines his or her own balance.
- - - - - - - - - - - - - - - - - - - - - - -
Akua fans can barrage me with hate mail if they wish.
People who know better than I can clarify or refute what I have said.
It seemed potentially important and useful to pass these thoughts
along. If not, I humbly apologize.
Have I filled up an entire digest with my incessant babbling?
Can I stop now? Yes. Thanks.
R23.message.onclose = "R23.mode.revert()"
R23