Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

maverick28

macrumors 6502a
Original poster
Mar 14, 2014
630
312
Hi all there,

I'm a complete novice in the area and I'm just learning from Hanaan Rosenthal, Hamish Sanderson "Learn AppleScript. A comprehensive guide, 3rd edition (2010)".


I came across this place in a section about constructing references of Part 2.Understanding how application scripting works. More on constructing references. The authors explain what relative references are (the subject about identifying elements), and then in the next section devoted to identifying a range of elements they write:



A third option is to use short references to the start and end elements themselves. For example,


tell application "TextEdit"
words 2 thru 4 of text of document 1
end tell

is really just shorthand for this:


tell application "TextEdit"
words (word 2) thru (word 4) of text of document 1
end tell

The start and end points are relative references, word 3 and word 6, that will be expanded using the reference to the container object, text of document 1 of application "TextEdit", as the base reference


I don't understand this passage. Related references define elements before or after another element. My questions:

1. How do we see that in this case word 3 and word 6 specifically are relative references if the script clearly states that word 2 through word 4 are the limiting points? Where word 5 got lost?

2. If indeed they are what's the author's point behind him claiming that "A third option is to use short references to the start and end elements themselves"? Why he calls it "references"? I don't get what is exactly being referred to and why these references are "short"? What is the difference between the command "words 2 thru 4 of text of document 1" and "words (word 2) thru (word 4) of text of document 1"?

Further on he continues:


In most applications, this isn’t a particularly useful way to write references, but some applications allow you to use different classes of elements for the start and end points. For instance, the following script obtains several words from a text frame in Adobe Illustrator:


tell application id "com.adobe.illustrator"
contents of words 2 thru 4 of text frame 1 of document 1
end tell


3. I don't get where these "different classes of elements for start and end points" in this example are?! I see just the class "words" being used. What are the "other classes"?

If some skillful user will grant me a part of his knowledge helping me to grasp this I would be very happy indeed.
 
Last edited:

mijail

macrumors 6502a
Oct 31, 2010
564
138
5 months later, but... if you are still interested in an answer I can try :D
 

maverick28

macrumors 6502a
Original poster
Mar 14, 2014
630
312
5 months later, but... if you are still interested in an answer I can try :D
Thanks mijail, I actually was able to figure it out after writing an email to the author (Hanaan Rosenthal, that is) himself. He explained it very thoroughly and more accessibly than in the book, admitting that the language of this and many other places were not very suitable because they tried to address it to all AppleScript mastering levels (from the beginners to the skilled scripters) resulting in a very long period of preparation for publication hence such inconsistency.
But it's regrettable that all AppleScript discussion boards, be it MacRumours or other forums, even mentioned previously in this Guide as helpful gravity harbors for Apple scripters (MacScripters etc.) are in the permanent state of idleness despite the great potential of AS itself. Sad.
 

Zazoh

macrumors 68000
Jan 4, 2009
1,518
1,122
San Antonio, Texas
Maverick28 - agreed, but there are a few of us who Use AppleScript and Automator daily. WE can revive it with patience and persistence of interest ... I only recently discovered this forum and I've been using the Mac Rumors site for years.

Both mentioned have a steep learning curve, as any scripting language does, but once through the curve, it all falls into place. I suspect there are more of us out there than meets the eyes.
 

mijail

macrumors 6502a
Oct 31, 2010
564
138
Thanks mijail, I actually was able to figure it out after writing an email to the author (Hanaan Rosenthal, that is) himself. He explained it very thoroughly and more accessibly than in the book, admitting that the language of this and many other places were not very suitable because they tried to address it to all AppleScript mastering levels (from the beginners to the skilled scripters) resulting in a very long period of preparation for publication hence such inconsistency.
But it's regrettable that all AppleScript discussion boards, be it MacRumours or other forums, even mentioned previously in this Guide as helpful gravity harbors for Apple scripters (MacScripters etc.) are in the permanent state of idleness despite the great potential of AS itself. Sad.

Good idea to ask directly to the author, and I'm impressed that he answered.

Anyway, I would suggest that the great potential is not in AppleScript itself but in Apple Events, which is what allows you to talk to applications. AppleScript as a language is a mess, a cute idea which doesn't work out (I guess there's a reason why "English-like" programming languages aren't common), and as you have seen yourself even documentation is plain bad.

So, if I had now to do anything non-trivial with AppleScript, I would try using any other scripting language which can be made to use Apple Events. The very Script Editor in macOS has been able to use JavaScript for some time now. I must say that I haven't really used JavaScript in this context (and very little in others), but it can NOT be worse than AppleScript - and if you know any other language from the "C family", JavaScript at least has the syntax *and semantics* you'd expect.

In fact, the very fact that JavaScript has appeared as an AppleScript alternative in the Script Editor makes me think that AppleScript is on its way out, after longer than a decade without evolution. Which is just another reason to learn anything else - because even if Apple Events disappeared, you at least still know a useful language.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.