9 Replies Latest reply on Nov 12, 2008 7:41 PM by (Simon_Paterson)

    Discussion: JS vs AS

    jhuddle123 Level 1
      Are there any discussions I can link to that describe at a high level differences between AS and JS, as far as InDesign scripting goes? Or does anyone have thoughts?

      I need to decide which to pursue for my company and want to get a sense of the payoff for spending the extra time learning JS (more functionality? better stability?)

      Also - anyone have advice on good resources for learning JS?

      Thanks much!
        • 1. Re: Discussion: JS vs AS
          Level 1
          Jim,

          For me it was two things:

          1. I'm much more comfortable with the syntax of JS than I ever was with AS. I was forever having to post messages here so that Shane could straighten out my syntax for me.

          2. I was faced with a user community that uses both platforms and JS works across both (about 99.9987% of the time -- I've run into one situation where I couldn't do something on Windows that worked on Mac: had to do with accessing mapped drives).

          The counter argument is that AS allows you to more easily integrate InDesign into a multi-application solution. The fact that I can't do that (outside of the Adobe suite, anyway) is probably a big factor in why the work I've ended up focusing on hasn't needed to do that.

          However, JS does allow you to work with text and binary files from any source, so you're not completely cut off from the outside world by choosing JS.

          Dave
          • 2. Re: Discussion: JS vs AS
            (Simon_Paterson) Level 1
            Jim,

            I have now worked with both AS and JS, and these are a few of my observations:

            * You can create interfaces in InDesign with scripts in 2 ways. There are the built-in UI objects within the DOM itself which can be accessed with Applescript, Javascript and VBScript. Then there is ScriptUI in Javascript which adds a lot more functionality to UI widgets and allows you to make far more comprehensive interfaces in Javascript using ExtendScript Toolkit. This has been a significant factor in my pursuit of Javascript over Applescript.

            * To debug Applescript line-by-line you need a very cool piece of software called 'Script Debugger'. It is not free, but certainly worth the money. It will be a necessary tool if you want to have a good Applescript development environment because I find line-by-line debugging is essential for successful scripting. On the other hand, the Javascript ExtendScript Toolkit is provided by Adobe for free, and it allows you to debug Javascript line-by-line.

            * One of the big reasons for choosing Javascript over Applescript is cross-platform compatibility. If this will ever be important, then the choice is clearly Javascript.

            * As Dave pointed out, Applescript cross-application scripting is far more simple than Javascript. This is not to say you cannot create cross Adobe application scripts with Javascript and ExtendScript (using the BridgeTalk object), it is just a lot more complicated. Having said that, once you work it out, the BridgeTalk messaging system is powerful. You can actually do a kind of cross-application background processing. The BridgeTalk applications like InDesign and Photoshop have a message queue which runs in the background and you can send JS scripts within a BridgeTalk object that gets processed by this queue. I've made a script which processes images in the background and sometimes the user is unaware that it is even running while they continue working.

            * Javascript is faster than Applescript. Using certain techniques you can make your Applescripts pretty efficient, but then if you use those same techniques with Javascript, too, it just enhances the speed of your JS scripts. I started with Applescript and ended up developing some really fast scripts. I'm using Javascript now and I've re-programmed many of those old AS scripts using the techniques that I learned while trying to make my AS scripts more efficient, and I've found the Javascripts run blazingly fast.

            * There are stacks of additional functions written to extend the Javascript language which can help when working with InDesign, such as string manipulation functions, roman-to-arabic number converters, and so on. These things are often harder to come by for Applescript.

            * Javascript gives you the ability to work with the awesome additional features provided by Rorohiko's Active Page Item Developer Toolkit (APID). If you make the decision to use Javascript, then this toolkit will get you very excited about the possibilities. (It is worth noting that APID does expose some properties and functions that can be accessed through AS, too, but it is not as comprehensive.) I am not affiliated with Rorohiko in any way, but for me this is a clear reason as to why I would choose JS instead of AS. APID adds additional 'events' that normally you do not have access to through scripting. These events allow you to do something when, for example, an image is selected or modified or deleted. This is only scratching the surface, there is a lot more. One of the best parts, and something which I've found makes deployment of my scripts so much easier, is that APID can convert a normal JS into a plug-in. It stops people from editing the script and changing something that may actually do harm to the document, rather than good. It is easy to add menu items using APID, and you can do this with CS, CS2, CS3 and CS4. What you end up with is a plug-in that you just copy into the Plug-Ins folder on each workstation and next time the user starts InDesign they have a new menu item and new functionality. APID is just normal JS and is inexpensive.

            * Javascript language has a lot of built-in methods for manipulating strings, for example, that Applescript doesn't have.

            * Javascript sin/cos/tan functions are much faster than Applescript's.
            • 3. Re: Discussion: JS vs AS
              Eric @ MCA Level 3
              One thing about AS--not necessarily a defense of it so much as a tip if you are going to use it--if you know a bit of unix you can make up for a lot of its library deficiencies (eg, sorting) via do script.

              For example:
              set AppleScript's text item delimiters to {ASCII character 10} -- always a linefeed
              
              set listString to myList as string
              set sortedString to do shell script "echo " & quoted form of listString & " | sort -n"
              • 4. Re: Discussion: JS vs AS
                (Simon_Paterson) Level 1
                That's a cool tip, Eric.
                • 5. Re: Discussion: JS vs AS
                  Eric @ MCA Level 3
                  Well, I got it off MacOSXHints so I can't really take credit. B)
                  • 6. Re: Discussion: JS vs AS
                    Level 1
                    Hi Jim,

                    One point that I'd add to the excellent ones made so far--the InDesign scripting object model is the same for either language. That is, unlike, say, Photoshop (which strongly favors JavaScript above AppleScript and VBScript), the same objects/properties/methods are exposed to all languages. The names differ a tiny bit, but the capabilities are the same.

                    Thanks,

                    Ole
                    • 7. Re: Discussion: JS vs AS
                      sstanleyau Level 4
                      On 12/11/08 11:49 PM, "Dave Saunders" <member@adobeforums.com> wrote:<br /><br />> I was forever having to post messages here so that Shane could straighten out<br />> my syntax for me.<br /><br />For newcomers around here, it's probably worth pointing out that a lot of<br />this was, I think, more due the way some things were implemented in InDesign<br />in the early days rather than any lack of the tenacity for which we all know<br />Dave. Thankfully things have improved a good deal in the implementation<br />since then, especially in the area of filtered references (whose clauses).<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au>
                      • 8. Re: Discussion: JS vs AS
                        sstanleyau Level 4
                        On 13/11/08 2:39 AM, "Simon Paterson" <member@adobeforums.com> wrote:<br /><br />> Apple have Xcode, a free development tool, which makes it easy to add cool<br />> interfaces to your scripts<br /><br />Your definition of easy is clearly different to mine ;-) IMO this has been<br />one of the big shortcomings on the AS side, although relief is near.<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au>
                        • 9. Re: Discussion: JS vs AS
                          (Simon_Paterson) Level 1
                          Hi Shane,

                          I do know what you mean. Dealing with the whole Xcode project thing was a steep learning curve for me just to put a GUI on an Applescript, but I do love Interface Builder a lot. I wish there was something like that for ScriptUI.

                          Simon