In article <MPG.dc83ab56b77580498979b@news.demon.co.uk>,
cyber_surfer@gubbish.wildcard.demon.co.uk (Cyber Surfer) wrote:
>With a mighty <AF837FB99668DC55@ppp131.itw.com>,
>perez@acm.org uttered these wise words...
>
>> Apple, as usual, addressed this problem several years ago. It's called
>> OSA (I think it stands for Open Scripting Architecture).
>
>Excellent. I guess I missed it coz I'm not a Mac developer. Since it
>has some relevance to this thread, I wonder how it compares with Tcl?
There's all kinds of ways to look at this comparison. If we go back to
the creating a button comparison then AppleScript loses because it is
extremely verbose. This is a typical snippet (syntax not guaranteed 100%)
repeat with w in {every word of every paragraph of window 1}
set the first character of w to 'T'
end repeat
On the other hand you can do exactly the same thing from MacPerl (I've
heard) so the syntax then acquires Perl's economy of expression. I would
also expect that Macintosh Common Lisp does OSA. I know that the GNU emacs
that runs on Mac also does OSA - I used it to get compilation errors from
CodeWarrior and parse them using the 'next-error' capabilities of emacs.
OSA is a strange hybrid of a thing. The closest analogy to it that I've
seen in the Unix world is Xt actions. If you could envision a way of
activating Xt actions via some IPC mechanism. I'm not a windows guy but
the people I know who are agree that windows has _nothing_ comparable to
OSA. It's another thing that keeps publishers on Macs.
In a nutshell (in case you're not familiar with Xtactions), the application
developer determines what capabilities a scripter might require. This is
called "factoring." The idea is, rather than allow the scripter to
activate GUI elements such as pushing buttons or selecting menu items,
allow the scripter to perform sensible operations. I've spent quite some
time scripting CodeWarrior so I'll use that as an example. In CodeWarrior,
the Mac IDE, you have commands Make Project, Remove Binaries, Set
Preferences of ___ to ___. Some of these correspond to menu items and some
of them don't. One that doesn't is "Save Error Window to file." There's
no corresponding menu item for it but the CW developers added it because it
was a sensible operation.
Let's define driving an application. Under Unix you typically drive an
application by opening a pipe to it and feeding it the commands that you
would type at it because most Unix things are keyboard-driven. This is the
entire paradigm behind expect. So, when you drive ed you feed it a string
of cryptic one character commands. You must get the command exactly right
because errorchecking is extremely difficult (although expect does make
this easier). And, of course, every utility/tool has a completely
different command set. So, you must know the "API" to awk,ed,sed,ls etc to
build fully functional glued together things. And you have no way to
control GUIs - they don't tend to be able to read from pipes. And GUIs
don't tend to have command languages anyway.
Tcl is just a better way of driving than the Bourne shell. If you embed
Tcl into your apps then you could do TkSends I suppose. But you have no
way of determining what are legal commands to Tksend. And, in general, I
haven't seen people use Tcl to express operations the way that
OSA/AppleScript does.
With AppleScript (the Script Editor, in fact) you can query the application
for what AppleEvent's it accepts and it gives you the syntax for activating
them. Whenever you execute a statement you get the results of that
statement. It's more of a dialogue with the application then you tend to
see with Tcl.
And the best thing is: your standard apps already do it. Quark Express,
CodeWarrior, Filemaker Pro, etc all support it. So you can use your
current favorite word processor to automatically process words. With Tcl
you tend to have to get a new word processor that was written in Tcl.
On the downside, I think AppleScript is slower than Tcl.
>
>> You have your choice of syntaxes (Perl, AppleScript or Frontier are
>> available or you can make your own). You can do it from C (but man!
>> does that hurt from what I hear).
>
>Even better. Is it possible to use Lisp? Tcl? You're saying that it
>can be done, but has anyone _actually_ done it yet?
I've used EmacsLisp a few years back. I imagine Macintosh Common Lisp can
do it. I wonder how well MacGambit supports OSA?
>
>Not that it matters. What's important is that Apple - and now MS -
>have a way of making the scripting language irrelevant. The choice is
>with the user, instead of hardcoded by the app developer. Now, if the
>Unix people could also use something like this...
Amusingly enough Apple ported OSA to AIX under the guise of their highend
network servers. So, you could send AppleEvents from you Mac to the server
to perform operations.
That's something else I forgot to mention. OSA is "network aware." So,
you could
tell application "FileMaker Pro" of machine "Sammy" in zone "Davis"
to activate
end tell
to start filemaker pro on that machine.
It's a fun capability to have when you're a nerd. :-)
|