1 Reply Latest reply on Jun 20, 2017 5:02 AM by Laubender

    [CS4 JS] beforeExport event listener question

    Skempy Level 1



      I have created an eventlistener in a startup script which simply writes to a log file every time anything is exported.


          var myEventListener1 = app.addEventListener("beforeExport", exportLog);


           function exportLog(){
            myNewDate = new Date;
            myDateString = myNewDate.toString();
            myExportTime = myDateString.slice(0,-9)
            var myString = app.documents[0].name + '\t' + myExportTime;
            myFile = File(c/Logs/export_log.txt");
            myFile.write(myString + '\n');



      As you can see, I can get the time of the export and the name of the document from which the export was done.


      Is it possible to get the path and name of the actual file exported or does the event listener not yet know this when the event handler is run?




      Simon Kemp

        • 1. Re: [CS4 JS] beforeExport event listener question
          Laubender Adobe Community Professional & MVP

          Hi Simon,

          it's years back that you asked and you may have found a solution elsewhere.
          So this reply is not especially addressed to you but to all who are doing a search on "beforeExport" and stop by.


          The answer is, that you can ask the event object itself when the handler function is running.
          Then you'll get all necessary info out of the event object itself.


          Do not run this from the ExtendScript Toolkit app. Just from InDesign's Scripts Panel.
          Tested with InDesign CS4 6.0.6 on Mac OS X 10.6.8.

          Lookup values for the enumerations here:

          Adobe InDesign CS4 (6.0) Object Model JS: Table of Contents, Enum Suite


          #targetengine beforeExportEventListening-1
          var myEventListener1 = app.addEventListener( "beforeExport", exportLog );
          alert("myEventListener1 added: "+myEventListener1);
          var c = 0 ; // Counter
          function exportLog(evtObject)
              var propValPairs = [evtObject], x, e ;
              for( x in evtObject )
                  propValPairs[propValPairs.length++] =
                  c +"\t"+ x +"\t"+ evtObject[x].toString();
                      propValPairs[propValPairs.length++] = c +"\t"+ x +"\t"+ e.message;
              Sample output:
              [object ImportExportEvent]
              0    fullName    ~/Desktop/Unbenannt-1.pdf
              0    format    Adobe PDF
              0    userInteractionLevel    1699311169
              0    eventType    beforeExport
              0    target    [object Document]
              0    currentTarget    [object Application]
              0    eventPhase    1701724789
              0    captures    true
              0    bubbles    true
              0    cancelable    true
              0    timeStamp    Tue Jun 20 2017 13:51:30 GMT+0200
              0    propagationStopped    false
              0    defaultPrevented    false
              0    id    6
              0    isValid    true
              0    parent    [object Document]
              0    index    0
              0    properties    [object Object]