Help me, please, to understand an explanation regarding AppleScript - a question from a dummie.

Discussion in 'Mac Programming' started by maverick28, Jul 1, 2016.

  1. maverick28, Jul 1, 2016
    Last edited: Jul 2, 2016

    maverick28 macrumors regular

    Mar 14, 2014
    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.
  2. mijail macrumors 6502a

    Oct 31, 2010
    5 months later, but... if you are still interested in an answer I can try :D
  3. maverick28 thread starter macrumors regular

    Mar 14, 2014
    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.
  4. Zazoh macrumors 6502a


    Jan 4, 2009
    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.
  5. mijail macrumors 6502a

    Oct 31, 2010
    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.
  6. Phil in ocala Suspended

    Phil in ocala

    Jul 14, 2016
    Mac's used to intuitive....they no longer are..PERIOD>
  7. mijail macrumors 6502a

    Oct 31, 2010
    I don't think you could say that AppleScript was ever intuitive. And if indeed it is being substituted by JavaScript, that is a *clear* improvement.

Share This Page