33 Replies Latest reply: Jan 12, 2014 11:52 AM by myDavey RSS

    ANN: automatic dialog after background export (exportPop.jsx)

    John Hawkinson Community Member

      A week or two ago, I wrote a script to pop up a dialog box after any background export, in response to the InDesign CS5 PDF export status thread. It doesn't seem like there's been feedback. I suspect it's sort of gotten lost in the noise in the general forum. So here we go again!

       

      Don't make me post it to InDesign Secrets!

       

      This script will automatically pop up a dialog box after every export finishes (PDF, IDML, whatever). It also makes sure that the Background Tasks window is turned on.

       

      You can download the script from here, or just paste in what follows and save as exportPop.jsx. See How to Install InDesign Scripts for installation instructions. If you save it in the Startup Scripts folder, it will run automatically when InDesign is started. Running it a second time disables it, if for some reason it causes problems.

       

      // exportPop.jsx -- pops up Background Tasks when you start an export
      //   and a modal dialog when an export finishes.
      // Beta version. Please post feedback at
      //   http://forums.adobe.com/thread/830572
      // John Hawkinson, 17 March 2011
      // Save in STARTUP SCRIPTS folder to start automatically.
      
      #targetengine session
      
      (function() {
          var
              old1 = app.eventListeners.itemByName("exportPop1"),
              old2 = app.eventListeners.itemByName("exportPop2");
              
          if (old1.isValid || old2.isValid) {
              if (old1.isValid) { old1.remove(); }
              if (old2.isValid) { old2.remove(); }
              alert("Export pop up window removed.\n"+
                  "Indesign will behave as normal.");
              return;
          }
          
          app.addEventListener("beforeExport", function() {
              var
                  tasksPanel = app.panels.itemByName("Background Tasks");
              if (tasksPanel) { tasksPanel.visible=true; }
          }).name = "exportPop1";
          
          app.addEventListener("afterExport", function(ev1) {
              var task, listener;            
              task = app.idleTasks.add({ name: "exportPop", sleep: 1000});
              listener = task.addEventListener(IdleEvent.ON_IDLE,
                  function(ev2) {
                      listener.remove();
                      task.remove();
                      alert(ev1.format+" export complete of "
                          +ev1.fullName+" at "+ev1.timeStamp);
                  });
          }).name = "exportPop2";
      
          alert("Export pop up window installed\n"+
              "Background Tasks will appear the start of an export\n"+
              "and a dialog will appear after each export complete.");
      }());
      
      
        • 2. Re: ANN: automatic dialog after background export (exportPop.jsx)
          Loic.Aigon Community Member

          Hi John,

           

          Very interesting ! Weeks ago I tried to catch events adding eventListener to backgroundTask and went into deadend. I was then sure background tasks could'nt be monitored but your script show me that indeed it is ! It opens me a lot of perspective

           

          Loic

          • 3. Re: ANN: automatic dialog after background export (exportPop.jsx)
            ChrisH94 Community Member

            Thanks for doing this - it works for me and removes one annoyance from CS5, that I would forget to open the window before exporting (and finding that the background export had hung, while I waited for something to happen). Now I have an immediate heads up!

             

            Thanks for sharing.

            • 4. Re: ANN: automatic dialog after background export (exportPop.jsx)
              davidblatner ACP

              re: don't make me post to indesignsecrets

               

              LOL! Well, honestly, there's a reasonable chance that it would find a wider audience there.

              Mind if I post it there, too?

               

              --david blatner

              (you can contact me directly if you want: david at indesignsecrets.com)

              • 5. Re: ANN: automatic dialog after background export (exportPop.jsx)
                Marijan Tompa [tomaxxi] UGM-MVPs

                Great work John!

                 

                I've got idea how to enhance this script even more


                You could create panel with list of finished files

                with all info (path, file size, file name, etc...)

                It would be great way to track finished files.

                 

                --

                Marijan (tomaxxi)

                http://indisnip.wordpress.com/

                http://inditip.wordpress.com/

                • 6. Re: ANN: automatic dialog after background export (exportPop.jsx)
                  Harbs. MVP

                  Hmm. Nice ideas!

                   

                  And buttons to open the resulting files would be very cool as well!

                   

                  Harbs

                  • 7. Re: ANN: automatic dialog after background export (exportPop.jsx)
                    Marijan Tompa [tomaxxi] UGM-MVPs

                    Yes Harbs, it would be great to have button to open resulting PDF!

                     

                    But this time, real panel (not ScriptUI palette) would be better!

                    Name: Background Tasks History

                    Maybe ability to edit PDF Metadata (XMP), FTP Upload...

                     

                    Cool feature: Send email notification after export complete

                     

                    --

                    Marijan (tomaxxi)

                    • 8. Re: ANN: automatic dialog after background export (exportPop.jsx)
                      Harbs. MVP

                      I'm liking the sound of this! You're whetting my appetite!

                       

                      Wanna do this together?

                      • 9. Re: ANN: automatic dialog after background export (exportPop.jsx)
                        John Hawkinson Community Member

                        Wow, you guys are really getting excited!

                         

                        I thought about adding a UI and decided that it would get too complicated, and it's hard to do really solid UIs in ScriptUI and I didn' want to go mess with ActionScript/FLEX/CSXS/etc. for something that nobody actually admitted to wanting to use :-).

                         

                        But I think you guys should go ahead! Seems like there's a market.

                        • 10. Re: ANN: automatic dialog after background export (exportPop.jsx)
                          Green4ever Community Member

                          Hi John,

                           

                          I used your script and it is working fine. It will give an alert message after completion of PDF export. This is nice, but when I copy some text from Indesign and pasting it into some other application like Word, ESTK... here also it gives a alert message. Actually do you want to include these cases also?

                           

                          Thanks,

                          Green4ever

                          • 11. Re: ANN: automatic dialog after background export (exportPop.jsx)
                            John Hawkinson Community Member

                            That is unexpected. What is the text of the alert message, or a screenshot?

                            • 12. Re: ANN: automatic dialog after background export (exportPop.jsx)
                              Green4ever Community Member

                              Hi John I got this error message while copying the text to MS word application.....

                              Copied to word.JPG

                              Thanks,

                              Green4ever

                              • 13. Re: ANN: automatic dialog after background export (exportPop.jsx)
                                John Hawkinson Community Member

                                Hmm. I wonder if it is better to filter these based on the export type, the empty document name, or both.

                                • 14. Re: ANN: automatic dialog after background export (exportPop.jsx)
                                  Marijan Tompa [tomaxxi] UGM-MVPs

                                  Sure Harbs!

                                   

                                  I'm in!

                                   

                                  --

                                  Marijan (tomaxxi)

                                  • 15. Re: ANN: automatic dialog after background export (exportPop.jsx)
                                    Marijan Tompa [tomaxxi] UGM-MVPs

                                    I think document name/path would be enough.

                                    Also you need to check what will happen when you

                                    copy stuff from InDesign to Illustrator because it will use PDF for transfer.

                                     

                                    --

                                    Marijan (tomaxxi)

                                    • 16. Re: ANN: automatic dialog after background export (exportPop.jsx)
                                      John Hawkinson Community Member

                                      It appears not.

                                       

                                      Under OSX, cutting and pasting to Illustrator doens't produce an export popup.

                                      Cutting and pasting text does, with a null document: "Sangam Clipboard Unicode Text Export export complete of  at Thu Mar 31 2011 01:02:35 GMT-0400."

                                      Dragging-and-dropping objects into Firefox produces: "InDesign Snippet export complete of /private/var/folders/kN/kNzi33+jHq0d7nd2+GTGGU+++TM/-Tmp-/Cleanup%20At%20Startup/InDesign %20Snippets/Snippet_303A4A9D5.idms at Thu Mar 31 2011 01:01:57 GMT-0400" and that is kind of awkward.

                                       


                                      I'm not sure what a reasonable filtering case is for these. I don't want to filter out snippets and I'm not sure filtering out termporary directories is wise. Their use by people is rather uncommon, but scripts may use them...blah.

                                      • 17. Re: ANN: automatic dialog after background export (exportPop.jsx)
                                        Mayhem SWE

                                        John Hawkinson wrote:

                                         

                                        I'm not sure what a reasonable filtering case is for these. I don't want to filter out snippets and I'm not sure filtering out termporary directories is wise. Their use by people is rather uncommon, but scripts may use them...blah.

                                        But would you really want your script to interupt execution of a script which writes to the temporary folder? I'd think not. At least I think it'd be a good idea to have your script honor the current value of app.scriptPreferences.userInteractionLevel as to not interfere with scripts that have requested it shouldn't.

                                        • 18. Re: ANN: automatic dialog after background export (exportPop.jsx)
                                          Harbs. MVP

                                          This is a classic example of how something very simple becomes not so straightforward when you get into the details...

                                           

                                          Harbs

                                          • 19. Re: ANN: automatic dialog after background export (exportPop.jsx)
                                            John Hawkinson Community Member

                                            Whoops, sorry for the delay. Here's a version that honors app.scriptPreferences.userInteractionLevel and also checks to make sure it is exporting either a PDF or IDML. I'd especially appreciate someone confirming this works properly for InDesign that's not US English.

                                             

                                            // exportPop.jsx -- pops up Background Tasks when you start an export
                                            //   and a modal dialog when an export finishes.
                                            // Beta version. Please post feedback at
                                            //   http://forums.adobe.com/thread/830572
                                            // John Hawkinson, 17 March 2011. This revision 20 April 2011.
                                            // $Id: f4055778c272f8d200d27f7ca7a63450dd1bdf7f $
                                            // Save in STARTUP SCRIPTS folder to start automatically.
                                            
                                            #targetengine session
                                            
                                            (function() {
                                                var
                                                    old1 = app.eventListeners.itemByName("exportPop1"),
                                                    old2 = app.eventListeners.itemByName("exportPop2"),
                                                    types = [ '$ID/InDesignMarkup', '$ID/Adobe PDF (Print)',
                                                        '$ID/Adobe PDF (Interactive)'],
                                                    i, typeFilter = {};
                                                    
                                                for (i=0; i<types.length; i++) {
                                                    typeFilter[app.translateKeyString(types[i])]=1;
                                                }
                                                    
                                                if (old1.isValid || old2.isValid) {
                                                    if (old1.isValid) { old1.remove(); }
                                                    if (old2.isValid) { old2.remove(); }
                                                    alert("Export pop up window removed.\n"+
                                                        "Indesign will behave as normal.");
                                                    return;
                                                }
                                                
                                                app.addEventListener("beforeExport", function() {
                                                    var
                                                        tasksPanel = app.panels.itemByName("Background Tasks");
                                                    if (tasksPanel) { tasksPanel.visible=true; }
                                                }).name = "exportPop1";
                                                
                                                app.addEventListener("afterExport", function(ev1) {
                                                    var task, listener;
                                                    if (app.scriptPreferences.userInteractionLevel===
                                                         UserInteractionLevels.NEVER_INTERACT ||
                                                        !typeFilter.hasOwnProperty(ev1.format) )
                                                 {
                                                        return;
                                                    }
                                                    task = app.idleTasks.add({ name: "exportPop", sleep: 1000});
                                                    listener = task.addEventListener(IdleEvent.ON_IDLE,
                                                        function(ev2) {
                                                            listener.remove();
                                                            task.remove();
                                                            alert(ev1.format+" export complete of "
                                                                +ev1.fullName+" at "+ev1.timeStamp);
                                                        });
                                                }).name = "exportPop2";
                                            
                                                alert("Export pop up window installed\n"+
                                                    "Background Tasks will appear the start of an export\n"+
                                                    "and a dialog will appear after each export complete.");
                                            }());
                                            

                                             

                                            I'm always suspicious of app.translateKey and app.findKeyStrings, especially when the latter returns stuff with spaces.. But there doesn't seem to be a better keystring for the PDF export formats.

                                             

                                            Incidently, ImportExportEvents and DocumentEvents have their own userInteractionLevels property. I figured it would probably be the value of the scriptPreference at the time the event was dispatched, but that doesn't seem to be the case. Any clues?

                                             

                                            Please note, Mayhem, that since app.scriptPreferences.userInteractionLevels seems to be different in every engine, I'm not sure there is much point in this check. But it does not hurt, so there we go.

                                             

                                            How's that CSXS extension coming, guys?

                                            • 20. Re: ANN: automatic dialog after background export (exportPop.jsx)
                                              John Hawkinson Community Member

                                              Anyone? Could someone test the above version in a non-English version of InDesign?

                                              • 21. Re: ANN: automatic dialog after background export (exportPop.jsx)
                                                Marijan Tompa [tomaxxi] UGM-MVPs

                                                Hey John,

                                                 

                                                Here is little update on our little work

                                                Export History UI.png

                                                 

                                                --

                                                Marijan (tomaxxi)

                                                • 22. Re: ANN: automatic dialog after background export (exportPop.jsx)
                                                  John Hawkinson Community Member

                                                  By the way, are you guys aware that the source to the Background Tasks panel is in the SDK in source/open/components/backgroundtaskspanel?

                                                  While I'm pretty sure I knew this fact at one time, I definitely forgot at the time you all were discussing this extension...

                                                  • 24. Re: ANN: automatic dialog after background export (exportPop.jsx)
                                                    myDavey Community Member

                                                    Hello,

                                                    First of all, Thanks John for this great script. It fits my work method perfectly!

                                                     

                                                    Now,

                                                    Although I should have posted this question here first, This is the 3rd place posting it... hoping to find someone that can help!

                                                     

                                                    Recently something very funny started happening in my InDesign (Mac OS 10.8 - InDesign CS6 8.01)

                                                    Everytime I copy text the backround task panel opens up like this:

                                                    Screen Shot 2013-12-31 at 8.07.05 PM.png

                                                     

                                                    It happens when copying using Cmd+C and when using context menu

                                                     

                                                    After a little digging I found that when I disable the exportpop script, I stopped getting the task panel!

                                                     

                                                    However:

                                                    1) I've been using this script for a while now and never had this problem.

                                                    2) Why should copying be considered like exporting?????

                                                     

                                                     

                                                    If anyone can shed light on this topic, I'd really appreciate it

                                                     

                                                    Thanks

                                                    Davey

                                                    • 25. Re: ANN: automatic dialog after background export (exportPop.jsx)
                                                      John Hawkinson Community Member

                                                      Huh. That's a first.

                                                      Do you have any idea what might have changed?

                                                      Upgrade of the OS or upgrade of InDesign?

                                                      Anything else?

                                                      Spyware installed by an arch-rival or the NSA?

                                                       

                                                      The script, of course, just uses InDesign's idea of an "export." Specifically, it registers a handler for InDesign's "beforeExport" event, and whenever InDesign decides there is going to be an export, it calls the beforeExport handlers. So it really lets InDesign decide.

                                                       

                                                      My best guess (which is not very good) is that this relates to clipboard stuff. There are some cases where copying something in InDesign and pasting it into some other program might cause InDesign to convert the copied items into IDML. I think this might happen if you copy/paste across two versions of InDesign that are simultaneously running? Now, this conversion to IDML is probably internally an "export," and so, in its own tortured way, could explain this. I would expect the export to happen on Paste and not on Copy, but I know the way clipboards work is actually way more complicated than you would think.

                                                       

                                                      So, are you running multiple copies of InDesign simultaneously?

                                                      Or alternatively, if you exit all other open apps, does it still happen? Perhaps you might need to trash your prefs again after doing so (I see from your earlier thread that you did try trashing your preferences. DId you do it by holding down Cmd-Opt-Shift-Control while starting ID?)

                                                       

                                                      I suppose there is probably some way to filter out these copying events.

                                                       

                                                      Try changing this portion of the script:

                                                       

                                                      app.addEventListener("beforeExport", function() {
                                                              var
                                                                  tasksPanel = app.panels.itemByName("Background Tasks");
                                                              if (tasksPanel) { tasksPanel.visible=true; }
                                                          }).name = "exportPop1";
                                                         

                                                       

                                                      to this:

                                                       

                                                      app.addEventListener("beforeExport", function(ev2) {
                                                              var
                                                                  tasksPanel = app.panels.itemByName("Background Tasks");
                                                              if (tasksPanel) { tasksPanel.visible=true; }
                                                      alert("debug: export format was "+ev2.format);
                                                          }).name = "exportPop1";
                                                         

                                                       

                                                      And report back what it says the format of the export was. Then we could modify the script to filter it out, hopefully.

                                                       

                                                      Or if that's not helpful, you could replace the above new alert() line with:

                                                       

                                                      var s = [];
                                                      for (i in ev2.properties) {
                                                        s.push(i+": "+ev2.properties[i]+
                                                          "("+ev2.properties[i].constructor.name+")");
                                                      }
                                                      alert("afterExport\n"+s.join("\n"));
                                                      

                                                      which will collect up all the properties of the event and display them in the alert, and we should be able to figure something out.

                                                       

                                                      Sorry for not seeing your earlier posts.

                                                      • 26. Re: ANN: automatic dialog after background export (exportPop.jsx)
                                                        myDavey Community Member

                                                        Hi John - Thanks for your reply!

                                                        I have no clue what might have changed - No upgrades done (and no spyware either )

                                                        I am not running multiple versions of InDesign

                                                        I trashed my prefs using both methods - keyCombo and manual deleting files

                                                         

                                                        Regarding for your debug-coding, here is what came up

                                                        First of all, I get 2 messages... maybe this is some clue?

                                                         

                                                        With code #1:

                                                        Screen Shot 2014-01-08 at 3.27.13 PM.pngScreen Shot 2014-01-08 at 3.26.47 PM.png

                                                         

                                                         

                                                         

                                                        With Code #2:

                                                        Screen Shot 2014-01-08 at 11.15.38 PM.pngScreen Shot 2014-01-08 at 11.15.44 PM.png

                                                         

                                                         

                                                         

                                                        I dont really understand what is going on... but maybe (hopefully) you do!

                                                         

                                                        Thanks for your help - and for the script

                                                        All the best,

                                                        Davey

                                                        • 27. Re: ANN: automatic dialog after background export (exportPop.jsx)
                                                          John Hawkinson Community Member

                                                          Hi, Davey:

                                                           

                                                            Sorry for the delay, I didn't mean to let this sit for so long.

                                                           

                                                          Anyhow, the debugging tells us that InDesign is doing two different exports of different type: Sangam Clipboard RTF Export and Sangam Clipboard Unicode Text Export. Again, I suspect it is a function of some other program running. If not two copies of InDesign, then InDesign and some Mystery App. So I'd suggest you try exiting everything else.

                                                           

                                                          Anyhow, it's easy enough to filter them out of the script.

                                                           

                                                          Right before this line:

                                                           

                                                                  if (tasksPanel) { tasksPanel.visible=true; }

                                                          try adding

                                                           

                                                          if (ev2.format.match(/Sangam/)) { return; }

                                                           

                                                          which will cause the handler to ignore formats that contain the word "Sangam."

                                                          Note that this depends on the "ev2" being included in this line:

                                                           

                                                          app.addEventListener("beforeExport", function(ev2) {

                                                           

                                                          which wasn't in the original version of the script, but which we added in the debugging.

                                                          Hopfullly that's clear?

                                                           

                                                          Let us know how it works!

                                                          • 28. Re: ANN: automatic dialog after background export (exportPop.jsx)
                                                            myDavey Community Member

                                                            Hi John

                                                            Thanks again for your help! - Greatly appreciated.

                                                             

                                                            Your added code to filter out the exporting worked great.

                                                            Regarding the issue in general, I dont have more than one InDeisgn on my computer, so how can it be running 2? I checked the "Activity Monitor" and it only shows one.

                                                            However, I had a few crashes recently, and I saw a very wierd thing which can point to such a direction:

                                                            • InDi crashes
                                                            • asks if to reopen
                                                            • I choose yes
                                                            • right away it crashes again!
                                                            • Asks for reopen
                                                            • I choose yes
                                                            • everything opens nicely!! ???

                                                             

                                                            I have no clue what this means... does this make any sense to anyone else?

                                                            Could it be that there is a different thing which can cause InDi to read things twice or something like that?

                                                             

                                                             

                                                            Thanks!

                                                            Davey

                                                            • 29. Re: ANN: automatic dialog after background export (exportPop.jsx)
                                                              John Hawkinson Community Member

                                                              Glad it worked for you.

                                                              Regarding the issue in general, I dont have more than one InDeisgn on my computer, so how can it be running 2? I checked the "Activity Monitor" and it only shows one.

                                                              As I said: Again, I suspect it is a function of some other program running. If not two copies of InDesign, then InDesign and some Mystery App. So not necessarily two InDesigns, but some other kind of interaction.

                                                               

                                                               

                                                              As for your double-crashing, yes, this (unfortunately) makes sense.

                                                              It means the crash is related to the document you had open the first time, which was somehow corrupt,

                                                              crashing InDesign. Then the next you start ID, it reopens the document from the crash-recovery version, but it turns out that version is corrupt too, so it also causes the crash. The 3rd time, ID gets smart and realizes it had tried to crash-recover the same document (unsuccessfully) and does not try again.

                                                               

                                                              So this is normal behavior for this variety of crash.

                                                              I think it's even probably correct behavior.

                                                              • 30. Re: ANN: automatic dialog after background export (exportPop.jsx)
                                                                myDavey Community Member

                                                                Thanks a lot John.

                                                                I understand what your suspection is now

                                                                I also understand the crash problem - I guess I just never saw it before.

                                                                 

                                                                I would like to troubleshoot this issue

                                                                Do you have any tips in how to troubleshoot this?

                                                                I guess trying with a new user account would be a start?

                                                                 

                                                                Thanks again

                                                                Davey

                                                                • 31. Re: ANN: automatic dialog after background export (exportPop.jsx)
                                                                  John Hawkinson Community Member

                                                                  A  new user account is always a good suggestion. I had also suggested exiting all open applications.

                                                                  • 32. Re: ANN: automatic dialog after background export (exportPop.jsx)
                                                                    myDavey Community Member

                                                                    Sorry, I had forgotten to mention that I had tried that

                                                                    I closed all apps and opened indi - not corrected.

                                                                    I restarted the computer and didnt open anything except indi - also didnt help.

                                                                     

                                                                    Thats why I jumped to a new user

                                                                     

                                                                    Thanks for your help!

                                                                    Davey

                                                                    • 33. Re: ANN: automatic dialog after background export (exportPop.jsx)
                                                                      myDavey Community Member

                                                                      Hi John

                                                                      I tried in a new user and the problem did not occur

                                                                      So, as you correctly suspected, it is a 3rd party interference... or maybe an InDesign setting...

                                                                       

                                                                      If anyone has any clue what can cause this, I would appreciate it

                                                                      But, thanks to Johns filter, it is not desperate.

                                                                       

                                                                      Thanks

                                                                      Davey