6 Replies Latest reply on May 27, 2016 7:49 AM by cbishop01

    Cannot get the Date modified and Output to work correctly

    cbishop01 Level 2

      I'm wanting the variables under the date to auto fill in when the document is saved.  That is The Date Created and Output date.  Here's what i have Happening in this script so far.  Once a file is saved it Creates this text frame and adds the File name, Date modified, Date ("Having trouble with this. Created, Date output") and App user name.  So far i cannot get the Value of the Date Created and ouput to show the actual dates.  It will add the Values just not show it as a date.

      Screen Shot 2016-05-23 at 12.07.34 PM.png

      I started this question here "Output date and Modified Date Scripting Question"  after the other question was answered.  So i moved it here so i can give credit to whom ever answers the question.  So far a big thank you goes out too "Trevorׅ and Laubender"

        • 1. Re: Cannot get the Date modified and Output to work correctly
          cbishop01 Level 2

          It would probably help if i showed you the actual Script.

          #targetengine "AutoStartScript"  
             
              app.addEventListener( "beforeSave" , doTextFrameOnPageOne );  
          
              function doTextFrameOnPageOne()  
           {  
           // Name of the Text Frame The Save information is in.   
              var frameName = "Save_Information";  
              var doc = app.documents[0];  
              var tempFrame = doc.textFrames.itemByName(frameName);  
          
          //-------------------->This is the Part that i cannot get to work proper<---------------------\\  
                
              var contentsOfFrame =  
                  doc.name+"\r"+  
                  getLogInUserName() +"\r"+  
                  getLocaleDateString() +"\r"+  
                  VariableTypes.CREATION_DATE_TYPE +"\r"+ // This is the first Problem
                  VariableTypes.OUTPUT_DATE_TYPE+"\r"+    // This is the second Problem
                  getAppUserName();  
          //--------------------> The "VariableTypes" <---------------------\\       
             
           // Change Properties of Text Frame.:  
               var tempFrameProperties =  
               {  
                  name : frameName ,  
                  contents : contentsOfFrame ,  
                  fillColor : "yellow50" , 
                  geometricBounds : ["-0.75in","-4.45in",".5in","-.75"]   
                  }  
                
                  if(!tempFrame.isValid)  
               {  
                var tempFrame = doc.pages[0].textFrames.add();  
                  tempFrame.properties = tempFrameProperties;  
                  };  
                   
                  tempFrame.contents = contentsOfFrame;  
                
              }  
                
              function getLogInUserName()  
           {  
          //  Computer User Name
               var userNameOSX = $.getenv("USER");  
               var userNameWindows = $.getenv("USERNAME");  
                
                  if(userNameWindows == null){return userNameOSX}  
                  else{return userNameWindows};  
                
              }  
                
              function getAppUserName()  
           {  
                  return app.userName;  
              }  
                
              function getLocaleDateString()  
           {  
                  return new Date().toLocaleString();  
              }
          
          • 2. Re: Cannot get the Date modified and Output to work correctly
            cbishop01 Level 2

            This was the last thing that was posted in the other post.  Quite simply put I just dont understand where to put the string so that it activates the below code.  I think i understand what i need to do i just dont know where or how to place any of the code to make this code show up with the actual dates where the other content is at.  All that code above places a text box with the information without anyone doing anything other than hitting the save button.  That way in files we have already created can get the above information without us having to manually place Text Variables in there for every file.  Is there another way to do this without the Variblestypes?  LIke above shows getLogInUserName,  getLocaleDateString etc.. is there another get"" for Output date and Creation Date?

             

             VariableTypes.CREATION_DATE_TYPE +"\r"+ // This is the first Problem  
                    VariableTypes.OUTPUT_DATE_TYPE+"\r"+    // This is the second Problem  
            
            
            11.  Re: Output date and Modified Date Scripting Question

             

             

             

             

            The fact of the matter you have to remember 2 points.

            Uwe's links explain why.

            1. textVar = ip[-1].textVariableInstances.add(LocationOptions.AFTER, ip[-1]) 
            2. textVar.associatedTextVariable = doc.textVariables.itemByName("Creation Date"); 

            Got it working?

             

            • 3. Re: Cannot get the Date modified and Output to work correctly
              cbishop01 Level 2

              Ok i altered it a little.  Below are the two parts i changed alittle.

              1st

                var contentsOfFrame =  
                      doc.name+"\r"+  
                      getLogInUserName() +"\r"+  
                      getLocaleDateString() +"\r"+  
                   
                      getCreationDateString() +"\r"+ // I ADDED THIS
                  
                      VariableTypes.OUTPUT_DATE_TYPE+"\r"+    // This is the second Problem
                      getAppUserName(); 
              

              2nd

                 function getAppUserName()  
               {  
                      return app.userName;  
                  }  
                    
                  function getLocaleDateString()  
               {  
                      return new Date().toLocaleString();  
                  }  
                  function getCreationDateString()  //I ADDED THIS ONE
               {
                      return new Date().toDateString(); //I ADDED THIS ONE
                  }
              

              I know the one i added on # 2 is bringing back the wrong date i'm sure because i have "new" date() is there a way to get the original date created to go where the Wed May 25 2016 is?  I tried return Date().toDateString(); but it makes the script not work at all.

              Screen Shot 2016-05-25 at 4.58.12 PM.png

              • 4. Re: Cannot get the Date modified and Output to work correctly
                cbishop01 Level 2

                Here's what i have and i'm stuck.

                Part one.

                 

                var contentsOfFrame =  
                        doc.name+"\r"+  //Working
                        getLogInUserName() +"\r"+  //Working
                        getLocaleDateString() +"\r"+  //Working
                        
                //-------------------->This is the Part that i cannot get to work proper<---------------------\\  
                // this Will display the Current date but I still not get it to display the Date Created or Output.  Any help PLEASE will be awesome.
                
                        getCreationDateString() +"\r"+ // NOT WORKING
                        
                       /* getOutPutDateString()+"\r"+ NOT CREATED YET*/
                       
                //--------------------> The "VariableTypes" <---------------------\\  
                
                        getAppUserName();  // Working
                
                
                

                 

                function getCreationDateString() {    
                var myVar;  
                        myVar = doc.textVariables.add(); 
                        myVar.VariableType=VariableTypes.CREATION_DATE_TYPE; 
                var Save_Information = Save_InformationTextFrame;  
                        Save_InformaionTextVar.associatedTextVariable= myVar; 
                /*return Date(' Created ').toString();*/  
                    } 
                
                
                

                 

                • 5. Re: Cannot get the Date modified and Output to work correctly
                  Trevorׅ Adobe Community Professional
                  var doc, tf, tvCd, tvMd, ip;
                  doc = app.activeDocument;
                  tf = doc.pages[0].textFrames.add({ geometricBounds: ['50mm', '50mm', '150mm', '150mm'] });
                  tf.contents = doc.name + '\r';
                  ip = tf.insertionPoints;
                  tvCd = ip[-1].textVariableInstances.add(LocationOptions.AFTER, ip[-1]);
                  tvCd.associatedTextVariable = doc.textVariables.itemByName("Creation Date");
                  ip[-1].contents = '\r';
                  tvMd = ip[-1].textVariableInstances.add(LocationOptions.AFTER, ip[-1]);
                  tvMd.associatedTextVariable = doc.textVariables.itemByName("Modification Date");
                  
                  1 person found this helpful
                  • 6. Re: Cannot get the Date modified and Output to work correctly
                    cbishop01 Level 2

                    Thank you so much.  This was totally kicking my butt. 

                    1 person found this helpful