2 Replies Latest reply on Nov 24, 2012 5:47 AM by BEGINNER_X

    Doubt in Document in Template

    BEGINNER_X Level 3

      Hi All,


      I am the beginner. I am studying through "InDesignCS3_ScriptingGuide_JS".


      In page no 13, there is script 'save a document as a template'


      Below script i am not able to understand, Can anyone explain it breifly if you willing.



      Lines are below.



      var myFileName;


      if(app.activeDocument.saved == true){


      //Convert the file name to a string.


      myFileName = app.activeDocument.fullName + "";


      //If the file name contains the extension ".indd", change it to ".indt".




      var myRegularExpression = /.indd/gi


      myFileName = myFileName.replace(myRegularExpression, ".indt");







      Thanks in advance for all you read my scripts.





        • 1. Re: Doubt in Document in Template
          Vamitul Level 4


          the script is very well commented..


          if(app.activeDocument.saved == true){

          • checks if the current active document is saved. This is important because "Unsaved documents have no full name".
          myFileName = app.activeDocument.fullName + "";
          • the fullName property of a document object returns a File object. This line converts that File object to a string (-containing the full path including the file name). The implementation is a bit unorthodox (don't think you will find it in many JavaScript books), but it works. Another way of doing it is: myFileName = app.activeDocument.fullName.toString()
          • checks if the string previously obtained contains ".indd". the indexOf() method of the String object returns -1 if the search string is not found. The problem here (and in the next lines) is if the file name is somenthing like: "myStrangeFile.indd.modifiedByStupidUser.indt"
          • for the rest of the lines I direct you to any general JavaScript beginner tutorials/books. A good reference: http://www.javascriptkit.com/jsref/
          1 person found this helpful
          • 2. Re: Doubt in Document in Template
            BEGINNER_X Level 3

            Thanks a lot vamitul....