Re: OSAX within tells
Re: OSAX within tells
- Subject: Re: OSAX within tells
- From: Jolly Roger <email@hidden>
- Date: Thu, 18 Jan 2001 16:02:57 -0600
- Replyto: email@hidden
on 1/18/2001 3:15 PM, Cal wrote:
>
Placing osax commands inside tell blocks has certain effects, some of
>
which may not be desirable:
>
>
- Anything that generates an interapplication message (Apple event)
>
inside a tell block -- including commands for scripting additions --
>
will generate an inter-process call, involving the Process Manager.
>
This may slow down the execution of your script.
Yes! Someone who "gets it"! Preach on, brother! :)
>
- Anything that generates an interapplication message (Apple event)
>
inside a tell block -- including commands for scripting additions --
>
will most certainly involve the event loop and at least some code in
>
the target application. In addition to the possibility of slowing
>
down the execution of your script, applications may do different (and
>
occasionally unexpected) things when handling the message, before it
>
even gets to the scripting addition.
I have experienced this *many* times. This is the main reason I try to
avoid using tell blocks to enclose more than is absolutely necessary in my
scripts.
>
- Some scripting addition commands (such as "display dialog") will
>
cause user interaction in that application. If that application
>
isn't frontmost, depending on the behavior of the particular
>
scripting addition, the user may have to bring that application to
>
the front to see the dialog box; in other cases, the dialog box will
>
appear in the background (not a Good Thing). OTOH, you may want to
>
do this because the user of your script will already have that
>
application in the foreground, so there won't be a problem.
>
But...remember that, if your script is executing as an application
>
(applet or droplet), it will run faster if the script itself is the
>
frontmost application (presuming that the target application will
>
work properly or efficiently if it's not frontmost; this will vary
>
from application to application).
I've also run into this problem. When a dialog is opened by a background
application, it can really screw things up!
>
- The possibility for terminology conflicts increases greatly when a
>
scripting addition's vocabulary is being compared with an
>
application's vocabulary, as opposed to a scripting addition's
>
vocabulary being compared with just AppleScript vocabulary. Remember
>
that specifying a tell block says to AppleScript, "Add these terms to
>
your language for a few moments." Developers of scripting additions
>
are fairly good about making an effort to stay clear of vocabulary in
>
other scripting additions (particularly the commonly-used ones), but
>
they cannot be expected to steer clear of all the tens of thousands
>
of terms in every scriptable application (PhotoScripter has over 2000
>
terms). I see conflicts of this nature just about every week.
I haven't experienced this one myself (probably because I am so careful to
avoid tell block abuse). But I *have* seen numerous newbies and more
experienced people on this list run into this problem.
>
So I'd give the following advice: Be cautious of calling scripting
>
additions in tell blocks, unless a) you know the behavior of the
>
target application, b) if that application will already be in the
>
foreground, and c) if you're only executing the command a small
>
number of times. (I'm not saying never to do this, but having an
>
arbitrary guideline like "it's good" or "it's bad" won't wash; you
>
should consciously have a good reason for doing it in each specific
>
case. To avoid problems, it's generally better to place calls to
>
osaxen outside tell blocks unless you want a specific effect, like
>
displaying a dialog in that application.)
Thank you for your thorough explanation, Cal. You have addressed each of
the concerns that I have when I advise people to avoid the habit of
enclosing everything in tell blocks. I usually do not have the time to go
that much into detail and explanation. If you don't mind, I'm going to
archive and use your comments in the future so I can provide a concise
explanation of why tell block over-usage is a bad thing.
JR