2 Replies Latest reply on Sep 30, 2016 8:17 AM by cbishop01

    Autosave Only after Text is edited?

    cbishop01 Level 2

      Hi all i have the below script from.  Its working Great i was just wondering if there was a way to make activate only if text has changed (being added or deleted etc..). I added the event listener and the function doAutoSave{}.  This version i have "For test" set to only activate before i save.  But my eventlisteners are not working. no matter what eventlistener i have in there it saves as soon as the Document is opened whether a change has been made or not.

       

       

      #targetengine "saveEvery1mn"  
      
      app.addEventListener( "beforeSave", doAutoSave );
      function doAutoSave(){
      
      main();  
      
      var filter = function() {  
        var w = "InDesign files:*.indd;",  
        m = function(f) {return /\.indd$/.test(f.name); };  
      return $.os[0]=="W"?w:m;  
      }  
      function main() {  
        var t = (new Date()).getTime();  
        var onIdleEventHandler = function(idleEvent) {  
        var doc = app.properties.activeDocument;  
      if ( !doc ) return;  
      if ( !doc.properties.fullName ) {  
        var f = File.saveDialog("You need to save your document now !", filter);  
      if ( f ) {  
        doc.save ( f );  
        }  
      return;  
        }  
        var t2 = (new Date()).getTime();  
      if ( t2-t > 1000 )  {  
        t = t2;  
        doc.save();  
        }  
        }  
        var myIdleTask = app.idleTasks.item("autoSave");  
      if ( !myIdleTask.isValid ) {  
        myIdleTask = app.idleTasks.add({name:"autoSave", sleep:100});  
        myIdleTask.addEventListener(IdleEvent.ON_IDLE, onIdleEventHandler, false);  
        }  
      }  
      }