30 Replies Latest reply on Jan 5, 2016 4:00 AM by tpk1982

    Indesign last saved version

    tpk1982 Level 4

      Hi,

       

      I am trying to get indesign last saved version. The below coding is tried. It is working fine until CS6. After CC version it is not giving correct answer.

       

      var filePath = app.activeDocument.filePath
      var fileName = app.activeDocument.name
      finalPath = filePath + "/" + fileName
      f = File(finalPath)
      IDversion= getFileVersion(f)
      
      
       if (IDversion >= "5.0" && IDversion < "6.0"){
              alert( "Document was created in indesign version CS 3")   }    
      
      
              
          else if (IDversion >= "6.0" && IDversion < "7.0"){
              alert( "Document was created in indesign version CS 4")       }
      
      
        else if (IDversion >= "7.0" && IDversion < "7.5"){
              alert( "Document was created in indesign version CS 5")       }
      
      
        else if (IDversion >= "7.5" && IDversion < "8.0"){
              alert( "Document was created in indesign version CS 5.5")       }
      
      
        else if (IDversion >= "8.0" && IDversion < "9.2"){
              alert( "Document was created in indesign version CS 6")       }
      
      
            else if (IDversion >= "9" && IDversion < "10.0"){
              alert( "Document was created in indesign version CC")       }
      
      
      else if (IDversion >= "10.0" && IDversion < "10.1"){
              alert( "Document was created in indesign version CC 2014")       }
      
      
      else if (IDversion >= "10.1" && IDversion < "10.2"){
               alert( "Document was created in indesign version CC 2014.1")       }
      
      
      
      
      else if (IDversion >= "10.2" && IDversion < "11.0"){
               alert( "Document was created in indesign version CC 2014.2")       }
      
      
      else if (IDversion >= "11.0" && IDversion < "12.0"){
              alert( "Document was created in indesign version CC 2015")       }
      
      
      
      
          else{
              alert( "Document was created in Indesign version lower than CS 3")       }
      
      
      
      
      function getFileVersion(f)
      {
         
      
      
          var IDversion;
          f.open('r');
          f.seek(29,0)
          IDversion = f.readch().charCodeAt(0);
      //~     f.seek(33,0)
      //~     IDversion1 = f.readch().charCodeAt(0);
      //~          if(IDversion1 >0)
      //~     {
      //~                 IDversion = IDversion + "." + IDversion1
      //~     }
      
      
          f.close();
          return(IDversion);
          }
      

       

      Please correct where i missed.

       

      Advance thanks,

      Karthi

        • 1. Re: Indesign last saved version
          Trevorׅ Adobe Community Professional

          Oh Dear, oh dear oh dear!

           

          Why are you using strings and not numbers!

          Change "5.0" to 5 etc.

          • 2. Re: Indesign last saved version
            tpk1982 Level 4

            Hi Trevor,

             

            I took IDversion as string because the version number may contain more than one period. See the below screenshot:

             

            Untitled.jpg

             

            I have a thought of using regular expression. Any suggestions?

             

            Regards,

            Karthi

            • 3. Re: Indesign last saved version
              Trevorׅ Adobe Community Professional

              Use parseFloat("9.4.5")

              I shall post something in a few minutes

              • 4. Re: Indesign last saved version
                Trevorׅ Adobe Community Professional

                This is my version

                // by Trevor http://www.creative-scripts.com
                // https://forums.adobe.com/message/8335570#8335570
                var doc, filePath, fileName, finalPath = false, IDversion;
                doc = app.properties.activeDocument;
                if (!doc) alert("Crash!"); // you could change the alert to exit if you are feeling nice
                filePath = doc.properties.filePath;
                if (filePath) {
                    fileName = doc.name;
                    finalPath = new File(filePath + "/" + fileName);
                }
                // Note using .fullName property as that will fail for converted (non saved files)
                IDversion= getFileVersion(finalPath);
                alert("Document was created in InDesign version " + IDversion);
                function getFileVersion(f) {
                    var IDversion = parseFloat(app.version); // if the file has not been save it was created on the current version!
                    if (f) {
                        f.open('r');
                        f.seek(29,0)
                        IDversion = parseFloat(f.readch().charCodeAt(0)); // see the parseFloat ;-)
                        f.close();
                    }
                    if (IDversion < 9) {IDversion = "CS " + (IDversion - 2);}
                    else if (IDversion < 10) {IDversion = "CC";}
                    // Presuming that Adobe keeps to their once a year update
                    // IMHO Adobe should learn a bit from Microsoft and make less often less buggy releases
                    else {IDversion = "CC 20" + (IDversion + 4);}
                    return(IDversion);
                }
                
                
                • 5. Re: Indesign last saved version
                  Trevorׅ Adobe Community Professional

                  By the way the root of your problem is your misunderstanding of the greater and less than functions.

                  What would you expect "100" < "2" ? Try it.

                  Try 100 < 2

                  Try "100" > "2"

                  Try 100 > 2

                  • 6. Re: Indesign last saved version
                    Trevorׅ Adobe Community Professional

                    One last point your script will show future versions as being CS3 or less

                    My one will fail from 2100 (no a big deal at my age :-)

                    I don't know what mine will do with CS3 or less files, it might put them as CC 20NaN or something else like that, I don't have any CS3 files to test on.

                    P.s. Please mark the question as answered

                    • 7. Re: Indesign last saved version
                      tpk1982 Level 4

                      Hi Trevor,

                       

                      AWESOME... It is working fine.. Need to check with CC 2015.

                       

                      In CS3 files, it is showing correct result.

                       

                      One quick question, why we need parseFloat in line 19. Because, we taking one single digit value in 'f', so i hope it wont need in that place. Please correct me if i am wrong.

                       

                      Thanks,

                      Karthi

                      • 8. Re: Indesign last saved version
                        Trevorׅ Adobe Community Professional

                        Yep! no need for the parseFloat as the number there is an integer.

                        So note the you won't get minor versions like cs5.5 it will return cs5 cc2015.2 will return cc2015

                        app.version gives you the minor version but that's not stored at that byte. I don't know if it is stored, search for the InDesign metadata documentation (google)

                         

                        Regards

                        Trevor

                        • 9. Re: Indesign last saved version
                          Trevorׅ Adobe Community Professional

                          This is an alternative approach

                          alert(app.activeDocument.metadataPreferences.getProperty("http://ns.adobe.com/xap/1.0/", "xmp:CreatorTool"));

                           

                          Flightcheck does seem to get the minor version see Which Version InDesign File Is an INDD File? FlightCheck It!

                          Couldn't check it out as my Flightcheck is crashing on me (probably need an update) I don't know how they are doing it but don't ask them because they will probably forward you to me.

                          • 10. Re: Indesign last saved version
                            Laubender Adobe Community Professional & MVP

                            Hi Trevor,

                            for the next minor version as represented in version 7.5 or 8.1 you can check f.seek(33,0) .

                            At least that worked for me with InDesign CS5.5 and my version of CS6 8.1 .

                             

                            ( I found that detail in the commented lines of the script Karthi posted )

                             

                            That will give you a string representation or a float:

                             

                            f.seek(33,0);
                            IDversion = IDversion +"."+ (f.readch().charCodeAt(0)); // String
                            IDversion = Number(IDversion); // Number
                            

                             

                            More details of the exact version number should be retrievable…

                            But I did not investigate this.

                             

                            Also see Jongware's script: [Ann] Identify Your InDesign File

                             

                            Uwe

                            • 11. Re: Indesign last saved version
                              Trevorׅ Adobe Community Professional

                              Hi Uwe

                               

                              Well spotted!

                              I have another method (1 liner) which is waiting for the moderators.

                              alert(app.activeDocument.metadataPreferences.getProperty("a namespace here see 9 above when it comes", "xmp:CreatorTool"));

                              Interesting that Jongware chose the method he did.

                               

                              Regards

                               

                              Trevor

                              • 12. Re: Indesign last saved version
                                Trevorׅ Adobe Community Professional

                                @Uwe,

                                looking at the ID file binary I couldn't find deeper info.

                                @Karthi This version will give the subversion

                                // by Trevor htpp://www.creative-scripts.com
                                // https://forums.adobe.com/message/8335570#8335570
                                var doc, filePath, fileName, finalPath = false, IDversion;
                                doc = app.properties.activeDocument;
                                if (!doc) alert("Crash!"); // you could change the alert to exit if you are feeling nice
                                filePath = doc.properties.filePath;
                                if (filePath) {
                                    fileName = doc.name;
                                    finalPath = new File(filePath + "/" + fileName);
                                }
                                // Note using .fullName property as that will fail for converted (non saved files)
                                IDversion= getFileVersion(finalPath);
                                alert("Document was created in InDesign version " + IDversion);
                                function getFileVersion(f) {
                                    var IDversion, subVersion;
                                    var IDversion = parseFloat(app.version); // if the file has not been save it was created on the current version!
                                    if (f) {
                                        f.open('r');
                                        f.seek(29,0)
                                        IDversion = f.readch().charCodeAt(0);
                                        f.seek(33,0);
                                        subVersion = f.readch().charCodeAt(0);
                                        IDversion = +(IDversion + "." + subVersion);
                                        f.close();
                                    }
                                    if (IDversion < 9) {IDversion = "CS " + (IDversion - 2);}
                                    else if (IDversion < 10) {IDversion = "CC";}
                                    // Presuming that Adobe keeps to their once a year update
                                    // IMHO Adobe should learn a bit from Microsoft and make less often less buggy releases
                                    else {IDversion = "CC " + (IDversion + 2004);} // to deal with the 2100 bug
                                    return(IDversion);
                                }
                                
                                • 13. Re: Indesign last saved version
                                  tpk1982 Level 4

                                  Hi Trevor & Uwe,

                                   

                                  Thank you so much for your ideas and suggestions. You both made me dancing in the floor.

                                   

                                  Regards,

                                  Karthi

                                  • 14. Re: Indesign last saved version
                                    tpk1982 Level 4

                                    Hi Trevor,

                                     

                                    I faced new problem. The script gave wrong result in MAC OS 10.5 but it is working fine in OS 10.6 and 10.9

                                     

                                    Is it all javscript OS based?

                                     

                                    Regards,

                                    Karthi

                                    • 15. Re: Indesign last saved version
                                      Trevorׅ Adobe Community Professional

                                      Hi Karthi

                                       

                                      I have no why that should be. What's the script doing in 10.5?

                                       

                                      Trevor

                                      • 16. Re: Indesign last saved version
                                        tpk1982 Level 4

                                        Hi Trevor,

                                         

                                        I created a document in CS3. I opened in CS5. But it shows the created version as CS5. But in OS 10.6 and above this problem not occurs.

                                         

                                        Thanks,

                                        Karthi

                                        • 17. Re: Indesign last saved version
                                          Trevorׅ Adobe Community Professional

                                          Open the ID file with Sublime Text on both 10.5 and 10.6

                                          Screen Shot 2015-12-31 at 18.13.52.png

                                          The last digit of the 2nd last entry of the 2nd line is the main version number 0b = 11 in dec and the last digit of the 1st entry in 3rd line is the minor number.

                                          You can compare how this comes out on the 2 os versions.

                                          My guess is regardless of the results of the above that the issue is to do with BOM filtering (google BOM character) this would throw off the results by 2 bytes and mean the for 10.5 you would need to change 29 to 31 and 33 to 35 so give that a go.

                                          Also I would guess that you have different ID versions on the different OS versions. Which ID versions are you using? 

                                          • 18. Re: Indesign last saved version
                                            tpk1982 Level 4

                                            Hi Trevor,

                                             

                                            Thanks for more information. I will install sublime text and check now. Yes in OS 10.5 i have CS3,4 and CS5. In OS 10.6 i have CS6.

                                             

                                            Advance Happy New Year wishes to you and your family.

                                             

                                            Regards,

                                            Karthi

                                            • 19. Re: Indesign last saved version
                                              tpk1982 Level 4

                                              Hi Trevor,

                                               

                                              Sublime Text is required OS 10.6 or advanced. So i tried in OS 10.6.8 machine. The below screen grabs i got:

                                              Screen shot 2016-01-01 at 12.16.42 PM.png

                                               

                                              Screen shot 2016-01-01 at 12.12.54 PM.png

                                               

                                              I ran CS3 file in CS5 it show wrong results. But it is giving correct result in CS6

                                               

                                              Regards,

                                              Karthi

                                              • 20. Re: Indesign last saved version
                                                Trevorׅ Adobe Community Professional

                                                Hi

                                                 

                                                Try change the following 2 lines

                                                 

                                                from

                                                 

                                                IDversion = f.readch().charCodeAt(0);

                                                subVersion = f.readch().charCodeAt(0);


                                                to


                                                IDversion = +f.readch().charCodeAt(0)

                                                subVersion = +f.readch().charCodeAt(0); 


                                                I.e. add a + with no space before the letter f in those 2 lines


                                                HTH


                                                Trevor

                                                • 21. Re: Indesign last saved version
                                                  tpk1982 Level 4

                                                  Hi Trevor,

                                                   

                                                  Again it showing wrong version

                                                   

                                                  I tried with change 29 to 31 and 33 to 35 option..not working.

                                                   

                                                  Regards,

                                                  Karthi

                                                  • 22. Re: Indesign last saved version
                                                    tpk1982 Level 4

                                                    Hi Trevor,

                                                     

                                                    I tried Jongware script it is showing correct version. Can we implement his logic into our script?

                                                     

                                                    //DESCRIPTION:Test InDesign file for version
                                                    // A Jongware Script 27-Jun-2013
                                                    
                                                    
                                                    iddFile = File.openDialog("Select an InDesign file", "InDesign file:*.indd;*.indt", true);
                                                    if (iddFile == null) exit(0);
                                                    f = File(iddFile);
                                                    filename = f.displayName;
                                                    if (f.open("r") == false) alert ("Unable to open this file!"); else {
                                                    f.encoding = "binary";
                                                    
                                                    
                                                    g = f.read (16); h = f.read(8);
                                                    j = f.read(1).charCodeAt(0);
                                                    k = f.read(4);
                                                    l = gl (f, j); l_m = gl (f, j);
                                                    m = f.length; f.seek (280); i = gl (f, 0)*4096;
                                                    f.close();
                                                    
                                                    
                                                    if (g != "\x06\x06\xED\xF5\xD8\x1D\x46\xe5\xBD\x31\xEF\xE7\xFE\x74\xB7\x1D")
                                                    {
                                                            alert ("This is not a valid InDesign document");
                                                    } else
                                                    {
                                                            if (l >= 3)
                                                            {
                                                                    if (l == 3)
                                                                            l2 = "CS";
                                                                    else if (l > 8)
                                                                    {
                                                                            l2 = "CC";
                                                                            while (l-- > 9) l2 += '.next';
                                                                    } else
                                                                            l2 = "CS"+(l-2);
                                                            }
                                                            if (l_m != 0)
                                                                    l2 = l2+"."+l_m;
                                                    
                                                    
                                                            if (m < i)
                                                                    alert ( "File: "+filename+"\r"+
                                                                                    "Reported type: "+h+"\r"+
                                                                                    "Reported version: "+l2+"\r\r"+
                                                                                    "Length of this file is less than expected -- it may be damaged!"
                                                                            +       "\r\r(A Jongware Script 27-Jun-2013)"
                                                                                    );
                                                            else
                                                            {
                                                                    if (parseFloat(app.version) < l)
                                                                    {
                                                                            if (parseFloat(app.version) < 4)
                                                                                    alert ( 'You cannot open "'+filename+'" because it was saved with a newer version of Adobe InDesign ('+l2+').\r'+
                                                                                                    'You must use that version or later to open the file. To then enable it to be opened in this version, export to IDML, then use InDesign CS4 to export to INX.\r'+
                                                                                                    '\r\r(A Jongware Script 8-Dec-2011)'
                                                                                                    );
                                                                            else
                                                                                    alert ( 'You cannot open "'+filename+'" because it was saved with a newer version of Adobe InDesign ('+l2+').\r'+
                                                                                                    'You must use that version or later to open the file. To then enable it to be opened in this version, export to IDML.\r'+
                                                                                                    '\r\r(A Jongware Script 27-Jun-2013)'
                                                                                                    );
                                                                    } else
                                                                            alert ( 'You can open "'+filename+'" with this version; it has been saved as Adobe InDesign ('+l2+').\r'+
                                                                                            '\r\r(A Jongware Script 27-Jun-2013)'
                                                                                            );
                                                            }
                                                    } }
                                                    
                                                    
                                                    function gl (a,b)
                                                    {
                                                            var c = a.read(4);
                                                            if (b == 2) return (c.charCodeAt(3)) + (c.charCodeAt(2)<<8) + (c.charCodeAt(1)<<16) + (c.charCodeAt(0)<<24);
                                                            return (c.charCodeAt(0)) + (c.charCodeAt(1)<<8) + (c.charCodeAt(2)<<16) + (c.charCodeAt(3)<<24);
                                                    }
                                                    
                                                    • 23. Re: Indesign last saved version
                                                      Trevorׅ Adobe Community Professional

                                                      This might do it.

                                                      // by Trevor htpp://www.creative-scripts.com
                                                      // https://forums.adobe.com/message/8335570#8335570
                                                      var doc, filePath, fileName, finalPath = false, IDversion;
                                                      doc = app.properties.activeDocument;
                                                      if (!doc) alert("Crash!"); // you could change the alert to exit if you are feeling nice
                                                      filePath = doc.properties.filePath;
                                                      if (filePath) {
                                                          fileName = doc.name;
                                                          finalPath = new File(filePath + "/" + fileName);
                                                      }
                                                      // Note using .fullName property as that will fail for converted (non saved files)
                                                      IDversion= getFileVersion(finalPath);
                                                      $.writeln("Document was created in InDesign version " + IDversion);
                                                      function getFileVersion(f) {
                                                          var IDversion, subVersion, j;
                                                          var IDversion = parseFloat(app.version); // if the file has not been save it was created on the current version!
                                                          if (f) {
                                                              f.open('r');
                                                              f.encoding = 'binary';
                                                              f.seek(24,0)
                                                              j = f.read(1).charCodeAt(0);
                                                              f.seek(29,0)
                                                              IDversion = gl(f,j);
                                                              f.seek(33,0);
                                                              subVersion = gl(f,j);
                                                              IDversion = +(IDversion + "." + subVersion);
                                                              f.close();
                                                          }
                                                          if (IDversion == 3) {IDversion = "CS"};
                                                          else if (IDversion < 9) {IDversion = "CS " + (IDversion - 2);};
                                                          else if (IDversion < 10) {IDversion = "CC";};
                                                          // Presuming that Adobe keeps to their once a year update
                                                          // IMHO Adobe should learn a bit from Microsoft and make less often less buggy releases
                                                          else {IDversion = "CC " + (IDversion + 2004);} // to deal with the 2100 bug
                                                          return(IDversion);
                                                      }
                                                      
                                                      function gl (a,b) //  by Jongware
                                                      {
                                                              var c = a.read(4);
                                                              if (b == 2) return (c.charCodeAt(3)) + (c.charCodeAt(2)<<8) + (c.charCodeAt(1)<<16) + (c.charCodeAt(0)<<24);
                                                              return (c.charCodeAt(0)) + (c.charCodeAt(1)<<8) + (c.charCodeAt(2)<<16) + (c.charCodeAt(3)<<24);
                                                      }
                                                      
                                                      • 24. Re: Indesign last saved version
                                                        tpk1982 Level 4

                                                        Hi Trevor,

                                                         

                                                        Thanks for your time.

                                                         

                                                        Sad thing, it is not working in lower versions. I created one document in CS3 and opened in CS4. It says "Document was created in CS4"

                                                         

                                                        I think lower than CS6 not supporting this object modes references.

                                                         

                                                        Thanks,

                                                        Karthi

                                                        • 25. Re: Indesign last saved version
                                                          Laubender Adobe Community Professional & MVP

                                                          Hi Trevor,

                                                          I tested your script from answer #23 on OSX 10.6.8 with a CS3 document opened in CS4.

                                                          And indeed the message was: "Document was created in InDesign version CS 4".

                                                           

                                                          However, Jongware's script identify.jsx (as shown in answer #22) started from CS4 detected the CS3 origin of the file when pointed at it on the hard disk.

                                                           

                                                          Uwe

                                                          • 26. Re: Indesign last saved version
                                                            Trevorׅ Adobe Community Professional

                                                            Hi Uwe and Karthi

                                                             

                                                            The earliest version of ID I have is CS5 on Windows and CS6 on Mac, so I can't work on this any more.

                                                            My suggestions are to either uses Jongwares script,  use the metadata method shown in 9 above or change the seeks to reads (adjusting the numbers) in my version maybe that would work.

                                                             

                                                            Trevor

                                                            • 27. Re: Indesign last saved version
                                                              Laubender Adobe Community Professional & MVP

                                                              Yes, Trevor!
                                                              Using the getProperty() method of the metadataPreferences of the Document seems to be the best method in the case of an opened older InDesign document not saved yet in the new version.

                                                               

                                                              I had success with this and the right string is returned (OSX 10.6.8). In the case of an opened CS3 document in CS4 it is: "Adobe InDesign 5.0".

                                                              To convert this to the right CS version or in other cases to the right CC version seems to be trivial. For me it's not necessary at all.

                                                               

                                                              If a user want more information about the opened document, he/she has just to look up the details by pressing cmd+About InDesign (Mac OSX) to get the most detailed picture from the history of the document. The protocol can be saved as soon as the document is saved in the newer version.

                                                               

                                                              If the aim is writing a startup script, that will give the user a brief warning or tries to make it harder to overwrite an older version document, I think, also this can be done. But in any case after opening an older version document the user is confronted with a Save As dialog that should tell him/her something ;-)

                                                               

                                                              Uwe

                                                              • 28. Re: Indesign last saved version
                                                                Laubender Adobe Community Professional & MVP

                                                                I tested a bit more with two different OSX versions (OSX 10.6.8 and 10.7.5) and a CS3 document and opened it in different versions of InDesign.

                                                                 

                                                                Trevor, your trick to get the file path of an opened doc from previous versions, not saved yet, is good for InDesign CS6 and higher.

                                                                Here my results:

                                                                 

                                                                // Open an InDesign CS3 doc in several higher versions and run this snippet:
                                                                
                                                                app.properties.activeDocument.properties.filePath;
                                                                
                                                                // RESULTS:
                                                                
                                                                // OSX 10.7.5
                                                                
                                                                // InDesign CS6 v8.1.0
                                                                // InDesign CC v9.3.0
                                                                // InDesign CC 2014.2
                                                                // => returns valid path with opened doc from lower version (not saved yet)
                                                                
                                                                
                                                                // OSX 10.6.8
                                                                
                                                                // InDesign CS4
                                                                // InDesign CS5
                                                                // InDesign CS5.5
                                                                // => returns EMPTY STRING
                                                                
                                                                
                                                                // OSX 10.7.5
                                                                
                                                                // InDesign CS5.5
                                                                // => returns EMPTY STRING
                                                                

                                                                 

                                                                Uwe

                                                                • 29. Re: Indesign last saved version
                                                                  tpk1982 Level 4

                                                                  Hi Trevor and Uwe,

                                                                   

                                                                  Is it possible to use Jongware script for active document? It ask to select file. Instead can we get opened document version?

                                                                   

                                                                  What are the modifications need to be made for his script?

                                                                   

                                                                  Regards,

                                                                  Karthi