5 Replies Latest reply on Mar 11, 2011 10:38 PM by John Hawkinson

    eventListeners for backgroundTasks?

    John Hawkinson Level 5

      I'd like to attach an eventListener to a backgroundTask (Document.asynchronousExport), and I can't seem to figure out what event types, if any, get sent there.


      There is a BackgroundTask.addEventListener(), so that would tend to suggest there are events. None of these events seem to fire:

      "beforeQuit", "afterQuit", "beforeNew", "afterNew", "beforeOpen", "afterOpen", "beforeClose", "afterClose", "beforeSave", "afterSave", "beforeSaveAs", "afterSaveAs", "beforeSaveACopy", "afterSaveACopy", "beforeRevert", "afterRevert", "beforePrint", "afterPrint", "beforeExport", "afterExport", "beforeImport", "afterImport."


      I realize I can basically get the same result from using Document.addEventListener() with eventType afterExport. That's what I will do instead..

      (Or I could use an idle event. But that would be a waste.)


      I guess Marijan Tompa seemed to note this in Jan in this post: Re: How To Prevent Recursive (Vicious Circle) Events.


      Any solutions? Or is this in fact just unimplemented? Has it been wishformed?



        • 1. Re: eventListeners for backgroundTasks?
          Marijan Tompa [tomaxxi] Level 4

          Hey John,


          Obviously, there is something wrong inside background task event listeners.

          It would be normal to use "afterExport" but, it's not working.

          Interesting thing that async call doesn't produce any events, so I think that's a bug.

          Hopefully it will be fixed in future versions of InDesign.


          Hope that helps.



          Marijan (tomaxxi)



          • 2. Re: eventListeners for backgroundTasks?
            John Hawkinson Level 5

            afterExport events appear to work for me.

            • 3. Re: eventListeners for backgroundTasks?
              Marijan Tompa [tomaxxi] Level 4

              Yes, it works fine for Application or Document object,

              but not for backgroundTasks



              Marijan (tomaxxi)

              • 4. Re: eventListeners for backgroundTasks?
                John Hawkinson Level 5

                Right, that's expected. But what other kinds of backgroundTasks are there?

                Anyhow, have you submitted a wishform request for this feature?

                • 5. Re: eventListeners for backgroundTasks?
                  John Hawkinson Level 5

                  Well, apparently there is an internal InDesign background Task called "Check Links," about which there are a bunch of weird properties.

                  For instance, if I run this quick hack script:

                  $.writeln("\n\n"+new Date());
                  a={}; function v(){var b=app.backgroundTasks,i,t;
                    for(i=b.length-1; i>=0;i--){
                         t=b[i]; a[t.id]=[t.id,t.name,t.isValid,t.percentDone,
                         t.documentName,t.parent.name,t.status]; }
                    return b.length; }
                  $.writeln("len "+v());
                  // for (j=0; j<1; j++) { v(); $.sleep(1)}
                  for (j in a) { $.writeln(a[j]); }

                  From the ESTK I get ~75 tasks:

                  len 75
                  2023,Check Links,true,0,,Adobe InDesign,RUNNING
                  2022,Check Links,true,0,,Adobe InDesign,RUNNING
                  2021,Check Links,true,0,,Adobe InDesign,RUNNING
                  2020,Check Links,true,0,,Adobe InDesign,RUNNING
                  2019,Check Links,true,0,,Adobe InDesign,RUNNING
                  2018,Check Links,true,0,,Adobe InDesign,RUNNING
                  2017,Check Links,true,0,,Adobe InDesign,RUNNING
                  2016,Check Links,true,0,,Adobe InDesign,RUNNING
                  2015,Check Links,true,0,,Adobe InDesign,RUNNING
                  2014,Check Links,true,0,,Adobe InDesign,RUNNING
                  2013,Check Links,true,0,,Adobe InDesign,RUNNING
                  2012,Check Links,true,0,,Adobe InDesign,RUNNING


                  And the task numbers only seem to increment when I poll -- that is, when I read the app.backgroundTasks array.


                  But if I run it from my javascript shell (change $.writeln to print), I get almost nothing. If I remove the commened out line and use j<1000, then I get ~10 or 20 tasks overall (All of which look like the above). And if I run it from ID's Scripts panel, I get no tasks at all. Pretty goofy.


                  Anyhow, to answer my own question, I submittd the following wishform bug report:

                  Concise problem statement:
                  SCRIPTING: a BackgroundTask has a .addEventListener() method, but no
                  events are dispatched to it.
                  Steps to reproduce bug:
                  In JavaScript, try to attach an eventListener to a background
                  asynchronous file export, and observe that it never runs:
                  (function() {
                          pdfFile=new File("~/Desktop/test.pdf"),
                          task = doc.asynchronousExportFile(ExportFormat.PDF_TYPE,
                              pdfFile, false),
                          events = ["beforeQuit", "afterQuit", "beforeNew", "afterNew",
                          "beforeOpen", "afterOpen", "beforeClose", "afterClose",
                          "beforeSave", "afterSave", "beforeSaveAs", "afterSaveAs",
                          "beforeSaveACopy", "afterSaveACopy", "beforeRevert",
                          "afterRevert", "beforePrint", "afterPrint", "beforeExport",
                          "afterExport", "beforeImport", "afterImport", "afterTask" ],
                          i, listeners = [];
                      for (i=0; i<events.length; i++) {
                          try {
                                  function(e) { alert("Caught "+events[i]); }));
                          } catch (e) {
                              $.writeln("failed to install "+events[i]+" for"+e);
                  Results: All published event types are successfully added, but
                    none are disaptched. "afterTask" is not supported.
                  Expected results: There should be an event that fires on a BackgroundTask.
                  Otherwise the addEventListener() method is pointless. If there are multiple
                  exports going on, it's necessary to be able to distinguish between them,
                  which is not available when listening for a document's afterExport event.