Paul Berkowitz <b************f_silcom.com> wrote:
> A 526-page Reference for Word AppleScript has just been released:
> This looks _very_ impressive indeed on first glance. 526 well-organized
> This is going to make a HUGE difference to Word's being scripted. And
> references are expected for the other apps too, according to the web site.
> There are sample scripts there too.
I'm not so impressed. It looks like this document is mostly just a
"translation" of the VBA online help, already found within Word itself.
And this "translation" is not very good - in many cases it fails to take
account of differences between VBA and AS, or between the VBA
implementation and the AS implementation of a thing.
The result is that there are some incoherencies that may trouble the
reader far more than assist.
For example, on pp. 18 and 19 a distinction is drawn between two
Set Range2 to Range1
which is said to cause range2 and range1 to refer to the same range
set Range2 to Range1
which is said to be shorthand for assigning the content of range1 to
range2, so that they may point to different locations or even different
documents. This is complete nonsense because the two expressions are the
very same expression!
But it is easy to see what has caused this mistake; in VBA, there *is* a
difference between "Set r2 = r1" and "r2 = r1", namely this very
difference. Clearly the author has copied a passage from a document
describing this difference in VBA, not realizing that there is no such
difference in AppleScript.
Similarly the document draws a distinction between "create range" and
"set range", saying that "set range" is used to "redefine an existing
text range object". But although this is true in VBA, it is not true in
the AS implementation; in fact, the two verbs do exactly the same thing
in AS, and the second has no effect upon the range it applies to (unlike
VBA, it is a function, not a method, i.e. it *returns* a *different*
range, rather than modifying *this* range).
In this case, as in many cases, we can actually see what the PDF was
translated from. It says:
> Use the set range command to redefine an existing text range
> object. The following example defines myRange to the first
> sentence in the document. The set range command redefines
> myRange so that it refers to the first sentence plus the
> next 10 characters.
The VBA online help shows us the source of this text:
> Use the SetRange method to redefine an existing Range
> object. The following example defines myRange to the current
> selection. The SetRange method redefines myRange so that it
> refers to current selection plus the next ten characters.
The incoherencies in the discussion here stem from the botched
trans**tation from VBA to AS.
Another good example of the problem is on p. 24, where we are told to do
a find using a text range's find object:
set content of find object of text object of active document to "blue"
set forward of find object of text object of active document to true
set myFind to execute find find object of text object of active document
The problem is that in AS, "execute find" does the wrong thing. In VBA,
myRange.Find.Execute changes myRange to the range of what was found. But
in AS it simply returns "true" (or "false") - the dictionary wrongly
claims that it returns a new range - and it does *not* change the target
range! Thus the above statement is utterly useless, and it would be
stupid to issue it, because there is no way to learn what was found. The
"translator" has been misled by VBA, and has not thought about how to
work with the AS implementation.
Even worse, in that particular example, the find will not even work
properly - it will not even return "true" or "false" correctly. The
correct way to do the find in that example is like this:
tell application "Microsoft Word"
tell active document
tell text object
tell (get find object) -- this is crucial!
set content to "blue"
set forward to true
If you say "tell find object" instead of "tell (get find object)", the
result will not even reliably be true or false - in fact, the script may
not even run. I did not find this out from the PDF; I found it out by
This PDF is going to help few readers and will mostly mislead people. It
is clearly a copy of existing VBA documentation, done by someone who has
not understood the subtleties of the AS language or the AS
implementation's crucial differences from the VBA implementation.
matt neuburg, phd = m********its.com, http://www.tidbits.com/matt/
AppleScript: The Definitive Guide
Read TidBITS! It's free and smart. http://www.tidbits.com