Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Why cant i get these 2 scripts to work in the same script?

Advisor ,
Jan 30, 2019 Jan 30, 2019

I have a Log file for when a file is Saved and when a File is PDF'd. Seperate i can get these to work. but when i place them in the same Script at best only 1 will work. How can i fix this?    

    app.addEventListener( "beforeExport", doPDFinfo );

    app.addEventListener( "beforeSave", doSaveINDDinfo );

   

   

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Logs Information when File is Saved ( InddSave.csv ) <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\\     

   

function doSaveINDDinfo(){

    var main = function() { 

      var ids ={}; 

      var el = app.eventListeners.itemByName('onAfterSave'), 

      onAfterExportHandler = function(evt){ 

      var doc = evt.parent, time; 

      if ( doc.constructor.name=="Document" ) { 

      if ( !ids[doc.id+"_"+evt.timeStamp] ) { 

      ids[doc.id+"_"+evt.timeStamp] = 1; 

      log ( evt ); 

      } 

      } 

      }; 

      !el.isValid && app.eventListeners.add('beforeSave', onAfterExportHandler).name = 'onAfterSave'; 

    } 

     

     

    var log  = function (evt){ 

      var headers = ["Indesign User Name", "Time", "Date", "Document Name", "Document path"]; 

      var exportFile = File ( evt.fullName ); 

      var f = File ( Folder("/Volumes/PPG/z-z MISC STUFF")+"/InddSave.csv" ); 

      var fOk = f.exists; 

      var d = (new Date()); 

      var m = d.getMonth()+1; 

      m<10 && m = "0"+m; 

     

      var hh = d.getHours(); 

      var pm  = hh>11; 

      pm && hh>12 && hh-=12; 

      hh<10 && hh = "0"+hh; 

      var mm = d.getMinutes(); 

      mm< 10 && mm = "0"+mm; 

     

      var doc = evt.parent; 

      f.open('a'); 

      !fOk && f.writeln ( headers.join(";") ); 

      f.writeln([app.userName, hh+":"+mm+" "+(pm? "PM":"AM"), m+"/"+d.getDate()+"/"+d.getFullYear(), exportFile.fsName, doc.name, doc.properties.fullName? doc.fullName : "Not saved" ].join(";") ); 

      f.close(); 

    }; 

     

     

    main(); 

   

    }

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Logs Information when File is exported ( exports.csv ) <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\\  

   

function doLOGinfo(){

    var main = function() { 

      var ids ={}; 

      var el = app.eventListeners.itemByName('onAfterExport'), 

      onAfterExportHandler = function(evt){ 

      var doc = evt.parent, time; 

      if ( doc.constructor.name=="Document" ) { 

      if ( !ids[doc.id+"_"+evt.timeStamp] ) { 

      ids[doc.id+"_"+evt.timeStamp] = 1; 

      log ( evt ); 

      } 

      } 

      }; 

      !el.isValid && app.eventListeners.add('afterExport', onAfterExportHandler).name = 'onAfterExport'; 

    } 

     

     

    var log  = function (evt){ 

      var headers = ["Indesign User Name", "Time", "Date", "Output Location and Name", "Document Name", "Document path"]; 

      var exportFile = File ( evt.fullName ); 

      var f = File ( Folder("/Volumes/PPG/z-z MISC STUFF")+"/exports.csv" ); 

      var fOk = f.exists; 

      var d = (new Date()); 

      var m = d.getMonth()+1; 

      m<10 && m = "0"+m; 

     

      var hh = d.getHours(); 

      var pm  = hh>11; 

      pm && hh>12 && hh-=12; 

      hh<10 && hh = "0"+hh; 

      var mm = d.getMinutes(); 

      mm< 10 && mm = "0"+mm; 

     

      var doc = evt.parent; 

      f.open('a'); 

      !fOk && f.writeln ( headers.join(";") ); 

      f.writeln([app.userName, hh+":"+mm+" "+(pm? "PM":"AM"), m+"/"+d.getDate()+"/"+d.getFullYear(), exportFile.fsName, doc.name, doc.properties.fullName? doc.fullName : "Not saved" ].join(";") ); 

      f.close(); 

    }; 

     

     

    main(); 

   

    }

TOPICS
Scripting
586
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 30, 2019 Jan 30, 2019

HI,

I will be 100% honest and state that I am not entirely sure what you code above is trying to do, seems to be more complicated than it needs to be, but as I said not sure what it is doing.

Based on the above I can only recommend some points that might help.

1. I would be tempted to make sure all functions have unique names.

2. Perhaps re-factor your code so you don't need to duplicate so much, your log function for example, could perhaps be changed to include a boolean - log ( evt, bSave)

This would enable you to change the headers array and also the file path without requiring to copy the whole function.

If you can provide more insight as to why you have the above set up it might be that we would be able to help you more.

Regards

Malcolm

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jan 31, 2019 Jan 31, 2019

Basically its to track to see when files were saved and exported. Its to cover the original authors butt.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 31, 2019 Jan 31, 2019
LATEST

my be you have to do something link this:

#targetengine doInfo
(function () { 
    if (app.eventListeners.itemByName ("doInfo").isValid) app.eventListeners.itemByName ("doInfo").remove();
    var myPDFinfoEventListener = app.eventListeners.add("beforeExport", doPDFinfo);   
    var myPDFinfoEventListener = app.eventListeners.add("beforeSave", doSaveINDDinfo);   
    myPDFinfoEventListener.name = "doInfo"; 
}) ();

function doPDFinfo(event)  {

}

function doSaveINDDinfo(event)  {

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines