12 Replies Latest reply on Mar 13, 2009 6:09 AM by Peter Kahrel

    Applescript or Javascript?

    smoothsea Level 3
      Hi, I'm on a Mac and have been using Applescript quite successfully to automate many common tasks, especially tables. The only thing I'm concerned about is whether I'd be more sensible to learn Javascript and use that instead.

      It seems that Javascript is much more like a 'real' programming language and I wondered if it has any other advantages (is it faster for example than Applescript). There might come a time when I'll be working on PCs rather than Macs and then I wouldn't be able to use Applescript at all (or would I?).

      Any thoughts or preferences from you scripting experts out there?

      Thanks,

      Malcolm
        • 1. Re: Applescript or Javascript?
          [Jongware] Most Valuable Participant
          >.. I wouldn't be able to use Applescript at all

          Precisely.

          JavaScript is the only language that works on
          i both
          platforms -- Mac native is AppleScript (and I'm pretty sure it is a 'real' programming language), Win native is VBScript (now there's some doubts :-) ). If you ever, EVER consider a platform transfer, or -- as I do -- work in a multi-platform office, use JS
          i exclusively.
          • 2. Re: Applescript or Javascript?
            sstanleyau Level 4
            On 11/3/09 9:12 PM, "jongware" <member@adobeforums.com> wrote:<br /><br />> If you ever, EVER consider a platform transfer, or -- as I do -- work in a<br />> multi-platform office, use JS   exclusively.<br /><br />On the other hand, if you ever plan to build workflows that involve more<br />than one app, and especially using non-Adobe apps (think spreadsheets,<br />databases, mail apps, command line, etc), you need to use AppleScript or VB<br />rather than Adobe's proprietary js engine.<br /><br />JS has a lot going for it: cross-platform, more built-in stuff like grep,<br />persistent engines, plus access to stuff like ScriptUI. But it also has<br />disadvantages -- you don't have droplets (my favorite UI because of its<br />speed and simplicity) like AppleScript, ESTK is, IMO, fragile and ugly, and<br />not a patch on a professional IDE like Script Debugger, and it has scope<br />issues.<br /><br />To me, cross-app is more important than cross-platform -- I generally only<br />use one platform, but I use and automate lots of apps. Others have different<br />priorities. Be thankful for the choice, and if you have the time, learn 'em<br />all. The hardest part of scripting InDesign is understanding the object<br />model, and that's much the same whatever the scripting language.<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au><br />AppleScript Pro Sessions <a href=http://scriptingmatters.com/aspro>
            • 3. Re: Applescript or Javascript?
              Level 1
              I've been scripting for 10 years, all on Macs. Scripts that started as simple single-use things eventually turned into full blown apps. I use XCode to build applescript based application that can drive InDesign as well as interface with Filemaker Pro, Interarchy (FTP), a full blown user interface, Distiller, shell commands, and the Finder.
              I know none of this stuff will never work on a PC, but integration across multiple apps is far more beneficial to me than having a "portable" javascript. I just figure I'll never need to use Windoze, I can do so much more with my Mac (plus my office is committed to Macs). You could make a similar argument for development on a PC, especially if you started there. I just found it was so much easier to build full apps with xCode + Applescript than starting from 0 with another programming language or platform.
              • 4. Re: Applescript or Javascript?
                liedzeit Level 2
                Learn JavaScript but do not forget AppleScript. I have quite a lot of projects where I use both. AppleScript mainly to trigger JavaScript (with doScript) and to talk to non-Adobe Apps. (And I also use RealBasic when I need a user interface that is a bit more complex than JS or AS allow me to build.)
                I personally was very sceptical about JavaScript but once you get used to it has some advantages over AS (mainly that there is no deceptive "simplicity".)
                Shane is right though with his remarks on ESTK. It is more fun working with AS.

                Ralf
                • 5. Re: Applescript or Javascript?
                  Eric @ MCA Level 3
                  I tend to stick with Applescript simply because I always find the syntax of Javascript pretty daunting by comparison. It can make revisiting a script you haven't had to edit in a year or two somewhat easier. (Provided you name your variables and comment well, of course.)

                  e.g. it is pretty simple to just read what is going on in stuff like this:
                  set pStylesList to every paragraph style whose name does not contain "["
                  
                  repeat with thisStyle in pStylesList
                  --Append "-old" to all current para styles except default
                  set name of thisStyle to name of thisStyle & "-old"
                  end repeat


                  Which is certainly not to say there's not more power locked in Javascript. There are a lot of rudimentary things, such as sorting that aren't part of the basic AS syntax, alas...

                  And a way to set a variable quicker would be nice! x := 0 like Pascal has, for "power" users or something.
                  • 6. Re: Applescript or Javascript?
                    smoothsea Level 3
                    Thank you all for your helpful comments.

                    Jongware I take your point about working in a multi-platform office. I've been self-employed for the last 10 years while my daughter was at school (I wanted to be at home for her when she came home), but now she's off to Uni and I'm keen to get back into the workplace again. Many people think that's crazy, but I miss the opportunity to bounce ideas around with other techies and also the chance to get my hands on the latest hardware and software (I'm still using CS2 on a G5 under Tiger if you can believe that).

                    The trouble is, I've been working Macs exclusively (and I love 'em) during that time and I know that it narrows considerably my options when it comes to job hunting. Publishing is a small industry in my little corner of the World and the few opportunities that appear are quickly snapped up by more multi-talented, less wrinkled people. Hence the need to upskill and maybe break out of publishing altogether.

                    On the other hand, Shane and Supermacguy make good points about multi-app scripting. I am also a big fan of Xcode, although I've only used it in a very limited way so far (not much time for R&D when your working day ends 5 minutes before bedtime). Is there not a similar environment for Windows? Or does all the hard work need to be done manually? Shane, when you say that the hardest part is learning the object model, do you mean how to address correctly the part of the document that you want to work on? If so, then I agree completely I've torn my hair out on many an occasion while trying to automate a simple task that takes two or three minutes to do manually!

                    The main theme here seems to be 'learn everything', which I suppose I should have expected! I'm off now to trawl the net for an Indesign/Javascript tutorial.

                    Thanks again,

                    Malcolm
                    • 7. Re: Applescript or Javascript?
                      sstanleyau Level 4
                      On 13/3/09 7:46 AM, "Malcolm Whild" <member@adobeforums.com> wrote:<br /><br />> Shane, when you say that the hardest part is learning the object model, do you<br />> mean how to address correctly the part of the document that you want to work<br />> on? <br /><br />Right -- knowing the language syntax and commands is a relatively easy<br />exercise, comparatively.<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au><br />AppleScript Pro Sessions <a href=http://scriptingmatters.com/aspro>
                      • 8. Re: Applescript or Javascript?
                        smoothsea Level 3
                        Yes it's a pity that the Indesign scripting documentation provided by Adobe is pretty complex, and yet strangely vague at the same time.

                        I'd like to see more real-world examples, fully worked through, with comments.

                        Perhaps I should write some

                        Malcolm
                        • 9. Re: Applescript or Javascript?
                          Eric @ MCA Level 3
                          This is one of the things that makes it easier to learn AS, imho. cmd-shift-L brings up a list of libraries, you open the InDesign CS2 reference and then use the search field to hunt up the keyword most likely to match what you're looking for. ESTK has something similar under the Help menu, but it is pretty kludgy by comparison.

                          If you're interviewing for jobs, knowing JS is definitely a more salable skill though, because a LOT of programs use JS.
                          • 10. Re: Applescript or Javascript?
                            smoothsea Level 3
                            Yes and the libraries are much improved since Tiger as well. You're also right about the English-sounding syntax making it easier to revisit old scripts.

                            Thanks,

                            Malcolm

                            --  

                            BookNZ Professional book design and production


                            Visit us on the Web at http://www.booknz.co.nz


                            29 Flavia Close

                            Torbay, Auckland

                            New Zealand


                            Telephone +64 9 473 8830

                            Fax               +64 9 473 0068



                            On 13/03/2009, at 12:48 PM, Eric @ MCA wrote:

                            A new message was posted by Eric @ MCA in

                            InDesign Scripting --
                              Applescript or Javascript?

                            This is one of the things that makes it easier to learn AS, imho. cmd-shift-L brings up a list of libraries, you open the InDesign CS2 reference and then use the search field to hunt up the keyword most likely to match what you're looking for. ESTK has something similar under the Help menu, but it is pretty kludgy by comparison.

                            If you're interviewing for jobs, knowing JS is definitely a more salable skill though, because a LOT of programs use JS.


                            View/reply at Applescript or Javascript?
                            Replies by email are OK.
                            Use the unsubscribe form to cancel your email subscription.


                            • 11. Re: Applescript or Javascript?
                              Harbs. Level 6
                              Peter's book is a great place to start with javascript in InDesign.
                              http://oreilly.com/catalog/9780596528171/

                              --
                              Harbs
                              http://www.in-tools.com
                              • 12. Re: Applescript or Javascript?
                                Peter Kahrel Adobe Community Professional & MVP
                                Thanks, Harbs.
                                CS3/4 update about to roll of the presses.

                                Peter