• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Javascript for automation quastions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Javascript for automation quastions


  • Subject: Re: Javascript for automation quastions
  • From: Rick Gordon <email@hidden>
  • Date: Wed, 17 Dec 2014 14:04:26 -0800

I have been working with AppleScript for a long time (though still not at a level comparable to many on this list), and took up JavaScript for web/ebook work within the last couple of years, and have found that just getting into it for a not-too-long while will iron out a lot of the confusion, leaving me sometimes screaming for AppleScript to do something as simply as can be done in JavaScript.

But for using JS in a system-wide manner, I might guess that in some ways, the analogy is closer to switching between AS and JS to script InDesign. (InDesign is actually my primary AS focus, as well.) There, you're dealing with an application object model that underlies both, and the similarities and differences become more readily apparent than the apples and oranges of system vs. web scripting.

In that respect, I found Peter Kahrel's Scripting InDesign CS3/4 with JavaScript very helpful, as it is quintessentially not a "teacher" book.

Random key takeaways (in no particular order of importance):

1) Practically speaking, "arrays" = "lists".

2) Declare all variables, whether you need to or not; undeclared variables are automatically global; declared variables are restricted to their scope (which mostly means between paired brackets).

3) Don't forget semicolons; you will, but you will feel pain.

4) With blocks equal tell blocks, but with blocks are considered bad form in modern JS (for reasons I won't bother with). It's generally preferred to create a variable to the level of access you need and go from their.

5) Hierarchy can be specified by chaining, such as: app.activeDocument.spread[5]

6) Coercing data to the correct type is even more important than in AS.

7) JavaScript is (in many, but not all ways) a "C-like" language, so much of the syntax (though not necessarily the way it works) is familiar to someone with some experience in C or Python.

8) In InDesign at least, some things that require repeat loops in AS can be done with a single statement.

9) JS is fussier about parentheses for if/else conditions; it's fussier about syntax in many ways.

10) JSLint.com (removing many of the overly fussy options) can be very helpful for debugging.

All that said, I would LOVE to see an actual book (or at least, a serious tutorial) on JS for AppleScripters. But googling javascript for coders will bring up some useful links.

Rick Gordon

---------------------
On 12/17/14 8:15 AM, has wrote:
2551 wrote:

> I recommended the wiki as a "bootstrap" for AppleScripters. You suggested it was lacking in some technical accuracy. I've no idea whether you're right about the latter, but even if so, the line you couldn't parse was meant to suggest that that doesn't necessarily matter.

Actually I stated that meaningful AE/OSA information is largely absent, period. That what limited information is given is wrong or unsafe is merely fluff on the cake. How you think these problems aren't a concern is beyond me. (Oh, and there's no point implying that I might be wrong or it's just my opinion: I have more knowledge and experience in this area than anyone else on the planet, and the work trail to prove it.)

I'm not criticizing you for sharing the link, only for failing to qualify it with a vital caveat. Anyone who tries to understand JXA using the misinformation and misconceptions currently in circulation is only going to end up with a head full of confusion. Welcome to Dunning-Kruger. Heck, the same critical caveat applies to Apple's own JXA (and SB) release notes which, as I've pointed out to confused learners elsewhere, are an absolute sack of lies. Seriously, every time the word "Array" gets used in JXA/SB documentation/discussion, Cook and Harris kill another kitten. For Dog's sake, think of the kittens!

Like I say, better to take an experienced AppleScripter, teach them the JavaScript language, and let them map knowledge of the former to the latter by their own study and experimentation. They'll develop a far more correct and useful understanding of the technology, and then might be able push back against some of that misinformation and misconception for others' benefit as well.


___________________________________________
RICK GORDON
EMERALD VALLEY GRAPHICS AND CONSULTING
___________________________________________
WWW: http://www.shelterpub.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden


References: 
 >Re: Javascript for automation quastions (From: has <email@hidden>)

  • Prev by Date: Re: Javascript for automation quastions
  • Next by Date: Re: OSAScriptController's stopScript action
  • Previous by thread: Re: Javascript for automation quastions
  • Next by thread: Re: Javascript for automation quastions
  • Index(es):
    • Date
    • Thread