31 Replies Latest reply on Dec 18, 2013 1:41 AM by Laubender

    JS ScriptUI CS4: How to create an indeterminate progress bar?

    Jim Birkenseer Level 1

      Hi Folks,

       

      Does anyone here know if ExtendScript (I'm using the CS4 flavor of ES) can produce an indeterminate (i.e., "barber pole") progress bar using ScriptUI's progressbar control? I've tried a number of value settings for the progress bar control in hopes that they would trigger the barber pole behavior, but so far, no luck.

       

      My current workaround is to "loop" the progress indicator. In other words, when the progress bar's value > maxvalue, I reset the value back to minvalue. Then rinse and repeat. Not really what I want, but the task being processed takes quite a bit of time, so I need to show some sign of something happening to the user.

       

      Thanks!

       

      -- Jim

        • 1. Re: JS ScriptUI CS4: How to create an indeterminate progress bar?
          ramkumar.vp Level 3

          Hi Jim,


          Please see below the sample progressbar script.


               myPrs = new Window('palette', 'Batch Processing');
               myPrs.orientation = 'column';
               myPrs.alignment = 'right';
               myPrs.ProcessHead  = myPrs.add('statictext',[40,0,260,25], "Batch Processing...");
               myPrs.Process = myPrs.add("progressbar",[40,40,260,65]);
               myPrs.Label = myPrs.add('statictext', [150,75,200,120], "0%");
               myPrs.Process.value = 0;

           

               var LENGTH = 4;

           

               myPrs.show();

           

               for(i=0;i<10;i++){
                   var PrCounter = 0;
                   ProgressBar(++PrCounter, i+1 , 10);
                   Function1();
                   ProgressBar(++PrCounter, i+1 , 10);
                   Function1();
                   ProgressBar(++PrCounter, i+1 , 10);
                   Function1();
                   ProgressBar(++PrCounter, i+1 , 10);
                   Function1();
               }

              

               function Function1(){
                   for(var i=0; i<1000000;i++){}
               }

              

               function ProgressBar(v, x, y){
                   var value = (Number(v) / LENGTH) * 100;
                   myPrs.Label.text = Math.round(value) + " % ";
                   myPrs.ProcessHead.text = "Batch Processing... [" + x + "/"+ y + "]";
                   myPrs.Process.value = value;
               }


          I think this script will solve your problem.


          Regards,

          Ramkumar .P

          • 2. Re: JS ScriptUI CS4: How to create an indeterminate progress bar?
            Jim Birkenseer Level 1

            Hi Ramkumar,

             

            Thanks for the reply, I really appreciate your help! Your idea is similar to what I am already using, which is fine as a workaround, but its not really what I'm after.

             

            What I'm trying to find out is if it is possible, using ExtendScript and ScriptUI, to display a indeterminate progress bar. In other words, one where my code would never have to increment its value during its processing. Basically, I'm looking for the spinning barber pole type of progress bar that spins without having to interact with it within my processing code. See the image below:

             

            BarberPole.png

             

            Thanks again!

             

            -- Jim

            • 3. Re: JS ScriptUI CS4: How to create an indeterminate progress bar?
              Harbs. Level 6

              I don't think you can use the standard progress bar for what you want.

               

              It should be possible to create a swf for that...

               

              Harbs

              1 person found this helpful
              • 4. Re: JS ScriptUI CS4: How to create an indeterminate progress bar?
                Jim Birkenseer Level 1

                Hi Harbs,

                 

                Thanks! I like your idea.

                 

                For now, though, I'm going to just leave my code as it is since there is no budget in the project for implementing the SWF idea.

                 

                Also, while I posted this message here, the project is actually for an Illustrator CS4 script, not an InDesign CS4 script. I decided to post on this forum because it has much more ExtendScript traffic than the AI forum. ;-)

                 

                At any rate, I was hoping that there might be a built-in in way (that I missed) to do this with ExtendScript's progressbar control...

                 

                Thanks again!

                 

                -- Jim

                • 5. Re: JS ScriptUI CS4: How to create an indeterminate progress bar?
                  absqua Level 4

                  Ancient thread, and not exactly what the OP wanted in the first place, but, after searching in vain on the web for a ready-made one, I made a basic indeterminate spinner-style swf and thought I would share it here: Dropbox link. This is a zipped archive of the swf and the source .ai file. The background color matches the normal window color on the Mac, but I don't know how it will look  on Windows.

                   

                  Jeff

                  • 6. Re: JS ScriptUI CS4: How to create an indeterminate progress bar?
                    Marc Autret Level 4

                    Hi Jim and Jeff,

                     

                    I can't find any practical solution to the original problem. It seems that an ExtendScript function call and a ScriptUI window cannot properly update synchroneously, except with a regular progressbar widget. I thought that a nonmodal window (='palette') might be fine, but I always get critical side effects using that approach, and generally the SWF is 'freezed' during the process. Curiously I found a kind of workaround using a pure modal dialog which mimics a nonmodal palette (!!) through the 'activate' event. But this still requires that the outer function perdiodically calls the update() method of the window from its own body, so this does not answer the question.

                     

                    Here is a first draft, based on the SWF that Jeff posted above and only tested on a Win platform. I'd really appreciate feedbacks on this from Mac users.

                     

                     

                    ////////////////////////////////////////
                    // SpinProgressBar Object
                    // Tested in ID CS4/CS5+ Windows only
                    ////////////////////////////////////////
                    
                    var SpinProgressBar = SpinProgressBar||function SB(/*str*/msg, /*fct*/process)
                    {
                        // Caches the function resources
                        // ---
                        SB.rc = SB.rc||{
                            swf: "CWS\tP&\x00\x00x\x9C\x8D\x9A\x7FL\x15W\x16\xC7\xCF\x11\xC5\x11)\xE2oQ\xD0'\x0F}O\x14\x7F\xA0\xE2o|\xCA\x11\x04\x05\x04\x14\x14Q\x11\xF1'\x82\n\" \xA2(j-\xB6(Hmw[\xDB&m\xD3\xCDnKbRLI\x7F\xC4&\xEBn\xDCdmk\xB3j\xAD\x9Bvwm\xC4\xAD1\xDB\x8D\xA9Y\x93\x8D\xFB\xBD#2\xE3\xF0\xB6\xEF\xF2\xC7H\x8Egf\xEE\xB9\xF3\xFD\xDC\xF3\x9D;TS\x9F\b\xA2!\xC5D\xA1\xA1$\x03\t?I\xBD\x1E?~\x1Cc0UV4\xC6\xE7\xCD~\xDB\xC5\xD4\xD9\xD9\xF9\x98\xC2\x07\xF5o-\xCE:s\xB5\xE3\x8F\x1FT\x9CZ\x121\xFA\xB7\xF1t\xAB_/bj\t\x0Ec\xFCs\x99\xC8G\xBDh;\xF9\xC2{\xE37\"\xB7\x11D\xDB\xA8\xEF\x97\xD4\xA7\r\xFF\x8D\x1F\\#\xA4\x7F\xCA\x97\xEDWnf\x97/j\xFAK[yb=\xB9\x8C\xDE=\x93\x8C\x86\xF6\x92\xD7O\xBD}\xA1\xF5\xF5\xD3\x85\xE45\xFA c\x90\x8B\xFA\xFC`\xBB\x8C\x8F\xCE\x95\x95\x9ExT\x15W\xD9\xD8q\xF9^\xC4wi\xA9\xD7\x90\x19\xFC4\xB3\xDE\xCA\xCCv\x8D\xC9(\xAF\r\xAE\xBA\xDAR\xD9q\xC1\xFD\xE3\xAD\xF6k\x13\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84\x8Fa \xC2\xC7qs\x1F\r\x0EcL\xA6c\xF2\x88\xFE\x07WG@D",
                            bkg: [232,232,232],
                            tmpFile: function FN(/*?str*/s)
                                {
                                    FN.file && FN.file.remove();
                                    FN.file = null;
                                    if( !s ) return null;
                    
                                    return FN.file = (function(fx)
                                    {
                                        fx = new File(''+fx);
                                        if( !fx.open("w") ) return null;
                                        fx.encoding = 'BINARY';
                                        fx.write(s);
                                        fx.close();
                                        return fx;
                                    })(Folder.temp+'/_'+(+new Date)+'.swf');
                                }
                            };
                    
                        // Creates the UI
                        // ---
                        var    rc = SB.rc,
                            w = new Window( 'dialog', '', undefined, {borderless:true} ),
                            p = w.add( 'panel' ),
                            fl = p.add( 'flashplayer', undefined, rc.tmpFile(rc.swf) ),
                            t = p.add( 'statictext', undefined, msg),
                            r;
                        rc.tmpFile(); // kills the tmp swf file
                    
                        // UI Skin/Style
                        // ---
                        with( w.graphics )
                            backgroundColor = newBrush(
                                BrushType.SOLID_COLOR,
                                [rc.bkg[0]/255, rc.bkg[1]/255, rc.bkg[2]/255, 1 ]
                                );
                        p.orientation ='row';
                        p.alignChildren = ['left','center'];
                        fl.preferredSize = [50,50];
                    
                        // Fire!
                        // ---
                        SB.win = w;
                        w.onActivate = function(){ process(); w.close(-1); };
                        r = -1==w.show();
                    
                        // Cleanup and return
                        // ---
                        SB.win = null;
                        w.onActivate = null;
                        rc = w = p = fl = t = null;
                    
                        return r; // true=>OK, false=>broken
                    };
                    
                    
                    ////////////////////////////////////////
                    // SAMPLE CODE
                    ////////////////////////////////////////
                    
                    var myHugeLoop = function()
                    {
                        var i = 500000;
                        while( i-- )
                            {
                            // you have to periodically call SpinProgressBar.win.update()
                            // but not necessary at each iteration
                            SpinProgressBar.win.update();
                    
                            Math.cos(i)*
                            Math.cos(i)*
                            Math.cos(i)*
                            Math.cos(i)*
                            Math.cos(i)*
                            Math.cos(i)*
                            Math.cos(i)*
                            Math.cos(i)*
                            Math.cos(i)*
                            Math.cos(i);
                            }
                    };
                    
                    if( SpinProgressBar("Currently processing a huge loop...", myHugeLoop) )
                        alert( "All is fine." );
                    else
                        alert( "The process has been broken by the user!" );
                    
                    

                     

                    @+

                    Marc

                    • 7. Re: JS ScriptUI CS4: How to create an indeterminate progress bar?
                      absqua Level 4

                      Marc,

                       

                      I verified that the swf looked right in a window before posting it, but didn't test it in an actual loop! It doesn't work very well. While it does look okay using this code:

                       

                      #targetengine "swftest"
                      var win = new Window('palette', "SWF Test");
                      with(win){
                          win.Flash = add('flashplayer',undefined,File("/Users/jeff/Desktop/temp/spinner.swf"));
                          win.Flash.preferredSize = [25,25];
                          win.Flash.visible = false;
                          win.Btn = add('button', undefined, "Go");
                      };
                      
                      win.Btn.onClick = function(){
                          var i = 200,
                              doc;
                          win.Flash.visible = true;
                          this.enabled = false;
                          doc = app.documents.add();
                          $.hiresTimer;
                          while(i--){
                              win.update();
                              doc.pages.add();
                          }
                          $.writeln($.hiresTimer/1000000);
                          win.Flash.visible = false;
                          this.enabled = true;
                      };
                      
                      win.center();
                      win.show();
                      

                       

                      Calling update() on the window in each iteration makes it take around three times as long to execute. Hardly worth it.

                       

                      Your code as posted makes a good-looking window, but errors on line 56 ("r = -1==w.show();"), saying only "Uncaught exception show", after myHugeLoop returns. (I'm running CS5 on the Mac.) I haven't teased apart the flow of control in your script to try to understand what's happening. Maybe because the window is closing itself from its own onActivate handler?

                       

                      If I substitute some InDesign activity (like "app.activeDocument.pages.add()") for the pure JavaScript Math stuff in your loop, the window shows fine but nothing happens—no pages get added—and myHugeLoop never returns, though I can exit it with Esc and get your alert. I don't understand this at all.

                       

                      Jeff

                      • 8. Re: JS ScriptUI CS4: How to create an indeterminate progress bar?
                        Marc Autret Level 4

                        Hi Jeff,

                         

                        Thanks, very interesting report. Mac and Win OS are definitely different in the way they deal with modal / nonmodal context (from ScriptUI).

                         

                        (...) errors on line 56 ("r = -1==w.show();"), saying only "Uncaught exception show", after myHugeLoop returns. (I'm running CS5 on the Mac.) I haven't teased apart the flow of control in your script to try to understand what's happening. Maybe because the window is closing itself from its own onActivate handler? (...)

                         

                        It seems to me a good assumption—although the code works on Win!

                        What if you remove w.close(-1) from the onActivate function?

                         

                        If I substitute some InDesign activity (like "app.activeDocument.pages.add()") for the pure JavaScript Math stuff in your loop, the window shows fine but nothing happens—no pages get added—and myHugeLoop never returns, though I can exit it with Esc and get your alert. I don't understand this at all.

                         

                        Technically, it is not possible to send any active dommand to the DOM—app.activeDocument.pages.add(), etc.—from within a ScriptUI modal dialog. We need a palette to do that, as in your sample code. But I have time consuming issues with palettes (on Windows) as soon as w.update() is required for the embedded SWF to be refreshed.

                         

                        It would be very helpful here to have clarifications from ScriptUI experts!

                         

                        @+

                        Marc

                        • 9. Re: JS ScriptUI CS4: How to create an indeterminate progress bar?
                          absqua Level 4

                          Technically, it is not possible to send any active dommand to the DOM—app.activeDocument.pages.add(), etc.—from within a ScriptUI modal dialog.

                           

                          That makes sense.

                           

                          If I take out w.close(-1), the window runs until I hit Esc, at which time I get your "The process has been broken by the user!" alert. So, closing via Esc is fine, but not via w.close(). I tried putting in a button as w.cancelElement and notifying that at the end of onActivate instead of closing the window directly, but still got the error on w.show().

                           

                          Dunno.

                          • 10. Re: JS ScriptUI CS4: How to create an indeterminate progress bar?
                            Marc Autret Level 4

                            Hi Jeff,

                             

                            Thanks for testing that.

                             

                            It's not the first time that significant differences appears between Mac and Win OS in the way ScriptUI deals with the onActivate/focus event. So, Mac doesn't support closing a window within the onActivate scope. Just to be sure on this point, here is an alternate version of my initial code that use a pure event handler on the 'focus' event:

                             

                             

                            ////////////////////////////////////////
                            // SpinProgressBar Object / Test 2
                            // Tested in ID CS4/CS5+ Windows only
                            ////////////////////////////////////////
                            
                            var SpinProgressBar = SpinProgressBar||function SB(/*str*/msg, /*fct*/process)
                            {
                                // Caches the function resources
                                // ---
                                SB.rc = SB.rc||{
                                    swf: "CWS\tP&\x00\x00x\x9C\x8D\x9A\x7FL\x15W\x16\xC7\xCF\x11\xC5\x11)\xE2o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x87\xAC\x06`F\x1A\xA9\xDE\xD1$N\xD2a\x07\t/\xD2\x11\xABI\x98\xB4\xBCD\r\xA6\xEE\xAD\x9C&:jY>\x93\x96StL\x11\x9Ea\xBD\xE1\x9F\xA6\xE3\xF6\x0F?\x8A\x96*\x1Cw\x014\xE1\xDD\x80Kx\x0F\x80\x12.G\xB9\xC2\x15(Qx/\xCA\x12\xAED)\xC2\xFB0|\xE1*\fY\xB8\x1A\xC3\x14\xAE\xC1\xD0\x84\xF7c8\x8A\x96\xE7\xB5\x8D\xC9\t=c\xE26^\xD0\x11v\xA3\x86\xB0Oj\xAF\xCA/j\x7F\xD0{I\xFB#l\x93\xA6A\x8D1N\xFD\x82l\xD7\x1F\xFA/\x14\xBE\x1B\xF2?\x1D@\xFE\x1E\xA3Y\xD7M\xB6h\x1AT\xC0\xD2\xAC\x05K\x0B=o\xC9\xDE\x84\xE5\f\x9Dp4\x89Vz\xC1\x01\xC2\xCB\xD4\xE8\x00\xE1,\x9D\xB4\xC9^E^\xA1\x17\x1D\x1Bd\xAF\xD2K\x0E\x87\xF7+j\xB2\xED\x02(\xD9\xFF\x9AN9\xBEw\xBEF\xA7mh\xA8\xC8\xEB\xD4l\xFB\xCB\x15u\xD69j\xB1\x7F\x01U\xB0\x1C\xC5\xB1\x16T\t\x1F\x00I\xC2u(T\xF8 \x8A\x13>\x84\x82\x84\xEBQ\x84\xF0a\f\\\u00F8\b\x06+\xDC\x80\x01\n\x1F\xC5\xA0\x84\x8Fa \xC2\xC7qs\x1F\r\x0EcL\xA6c\xF2\x88\xFE\x07WG@D",
                                    bkg: [232,232,232],
                                    tmpFile: function FN(/*?str*/s)
                                        {
                                            FN.file && FN.file.remove();
                                            FN.file = null;
                                            if( !s ) return null;
                                        
                                            return FN.file = (function(fx)
                                            {
                                                fx = new File(''+fx);
                                                if( !fx.open("w") ) return null;
                                                fx.encoding = 'BINARY';
                                                fx.write(s);
                                                fx.close();
                                                return fx;
                                            })(Folder.temp+'/_'+(+new Date)+'.swf');
                                        }
                                    };
                            
                                // Creates the UI
                                // ---
                                var    rc = SB.rc,
                                    w = new Window( 'dialog', '', undefined, {borderless:true} ),
                                    p = w.add( 'panel' ),
                                    fl = p.add( 'flashplayer', undefined, rc.tmpFile(rc.swf) ),
                                    t = p.add( 'statictext', undefined, msg),
                                    ehWrapProcess = function EH_WRAP_PROCESS(/*ev*/)
                                        { this.removeEventListener('focus', EH_WRAP_PROCESS); process(); this.close(-1); },
                                    r;
                                rc.tmpFile(); // kills the tmp swf file
                            
                                // UI Skin/Style
                                // ---
                                with( w.graphics )
                                    backgroundColor = newBrush(
                                        BrushType.SOLID_COLOR,
                                        [rc.bkg[0]/255, rc.bkg[1]/255, rc.bkg[2]/255, 1 ]
                                        );
                                p.orientation ='row';
                                p.alignChildren = ['left','center'];
                                fl.preferredSize = [50,50];
                                
                                // Fire!
                                // ---
                                SB.win = w;
                                w.addEventListener('focus', ehWrapProcess);
                                r = -1==w.show();
                            
                                // Cleanup and return
                                // ---
                                SB.win = null;
                                rc = w = p = fl = t = null;
                                
                                return r; // true=>OK, false=>broken
                            };
                            
                            
                            ////////////////////////////////////////
                            // SAMPLE CODE
                            ////////////////////////////////////////
                            
                            var myHugeLoop = function()
                            {
                                var i = 500000;
                                while( i-- )
                                    {
                                    // you have to periodically call SpinProgressBar.win.update()
                                    // but not necessary at each iteration
                                    SpinProgressBar.win.update();
                                    
                                    Math.cos(i)*
                                    Math.cos(i)*
                                    Math.cos(i)*
                                    Math.cos(i)*
                                    Math.cos(i)*
                                    Math.cos(i)*
                                    Math.cos(i)*
                                    Math.cos(i)*
                                    Math.cos(i)*
                                    Math.cos(i);
                                    }
                            };
                            
                            if( SpinProgressBar("Currently processing a huge loop...", myHugeLoop) )
                                alert( "All is fine." );
                            else
                                alert( "The process has been broken by the user!" );
                            
                            

                             

                            Can you confirm that this still doesn't work on Mac?

                             

                            @+

                            Marc

                            • 11. Re: JS ScriptUI CS4: How to create an indeterminate progress bar?
                              absqua Level 4

                              Marc,

                               

                              Still the same error, I'm afraid.

                               

                              May I ask how you intended to use this? I was going to use it in those situations where I was doing something that was going to take awhile, but not in a loop—for me, these are normally xml-related things, like evaluateXPathExpression() or xml rules. If I had a loop to process I would just use a normal progress bar. But, since it only looks OK if you update it regularly, the situation that calls for it is the same situation where it doesn't really work...

                               

                              Jeff

                              • 12. Re: JS ScriptUI CS4: How to create an indeterminate progress bar?
                                Marc Autret Level 4

                                May I ask how you intended to use this? I was going to use it in those situations where I was doing something that was going to take awhile, but not in a loop—for me, these are normally xml-related things, like evaluateXPathExpression() or xml rules. If I had a loop to process I would just use a normal progress bar. But, since it only looks OK if you update it regularly, the situation that calls for it is the same situation where it doesn't really work...

                                 

                                Jeff

                                 

                                You are quite right. Even if it worked, there would be little point in using it. I was just thinking about an Array.sort(...) callback function. When we process a huge sort, there is no way to predict the execution time but we know that the comparison function is repeatedly invoked by the sort algorithm. Suppose that I use myArray.sort(myCompFunc), myCompFunc could update an inner (static) counter and call SpinProgressBar.win.update() each time the counter reach a certain value. Something like:

                                 

                                 

                                var myCompFunc = function F(a,b)
                                {
                                     F.counter = F.hasOwnProperty('counter') ? ((1+F.counter)%100) : 0;
                                     if( 0 == F.counter ) SpinProgressBar.win.update();
                                
                                  return a-b;
                                };
                                

                                 

                                Does this make sense?

                                 

                                @+

                                Marc

                                • 13. Re: JS ScriptUI CS4: How to create an indeterminate progress bar?
                                  absqua Level 4

                                  Yes. Wonderful. The project I was going to use it in now uses a somewhat complicated sort—sorting xmlElements according to their page location, partly based on the function you posted in this thread—and it takes a long time. I should be able to show the flashplayer in my (non-modal) window before the sort commences and update it in the manner you demonstrated.

                                   

                                  I'm glad I asked! Thanks!

                                  • 14. Re: JS ScriptUI CS4: How to create an indeterminate progress bar?
                                    Vamitul Level 4

                                    sorry to bump an old thread, but i was hoping someone made some progress in this matter.

                                    i'm in the same situation, i need a indeterminate progress bar for a script, i'we tried using a swf for it, but it only shows after the script has finished running. I can't update de palette/dialog/whatever very often, since my script basicly exports about 5 or 6 PDF's form very large documents, so the ony time i can update is when one PDF is exported, and that will not do.

                                    • 15. Re: JS ScriptUI CS4: How to create an indeterminate progress bar?
                                      Laubender Adobe Community Professional & MVP

                                      @Vamitul – it's not about ScriptUI and might be no real help, but you could run the export in the foreground where the "normal" UI progress bar is showing up with the page names and some other statements…

                                       

                                      For that use the old "exportFile()" method instead of the "asynchronousExportFile()" method.

                                       

                                      Uwe

                                      • 16. Re: JS ScriptUI CS4: How to create an indeterminate progress bar?
                                        Jim Birkenseer Level 1

                                        Vamitul,

                                         

                                        I agree with what Laubender wrote...use the document.exportFile() function to do the exporting. I use that frequently. This gives you the progress bar for free.

                                         

                                        -- Jim

                                        • 17. Re: JS ScriptUI CS4: How to create an indeterminate progress bar?
                                          Vamitul Level 4

                                          well.. nope .. does not work. here is the code i'm using:

                                          var myFolder=Folder(app.activeDocument.filePath).selectDlg("PDF folder:");
                                          if (myFolder){
                                          for (var i=0; i<app.documents.length; i++)
                                          {    myDoc=app.documents[i];
                                          
                                          
                                               expFile = File( myFolder+ '/'+ myDoc.name + '.pdf' );
                                              myDoc.exportFile(ExportFormat.PDF_TYPE,expFile,false,app.pdfExportPresets.itemByName("GU"));
                                              }
                                          alert("Done");
                                          }else{alert("Canceld");}
                                          
                                          • 18. Re: JS ScriptUI CS4: How to create an indeterminate progress bar?
                                            Laubender Adobe Community Professional & MVP

                                            @Vamitul – hm, basically exportFile() should work the way I described.

                                             

                                            Just try the following script I posted two years ago at InDesign Secrets:

                                             

                                            //ExportPDF_in_Foreground.jsx
                                            //Uwe Laubender
                                            /**
                                            * @@@BUILDINFO@@@ ExportPDF_in_Foreground.jsx !Version! Wed Jun 23 2010 17:08:10 GMT+0200
                                            */
                                            //DESCRIPTION:PDF-Export in foreground (old school like in InDesign CS4)
                                            
                                            if(app.documents.length>0){
                                                var d=app.activeDocument;
                                                };
                                            else{
                                                alert("Please open a document to execute export to pdf. STOP.");
                                                exit();
                                                }
                                            if(d.saved == false){
                                                alert("Save your document first before executing export to pdf. STOP.");
                                                exit();
                                                };
                                            
                                            var pdfPath = Folder.selectDialog("Folder to save pdf:");
                                            var pdfName = d.name+".pdf";
                                            
                                            var userDefFileName = prompt("File name:",pdfName,undefined);
                                            
                                            if(userDefFileName == null){
                                                exit();
                                                };
                                            
                                            var pdfFullName = pdfPath+"/"+userDefFileName;
                                            
                                            if(File(pdfFullName).exists){
                                                c=confirm("The PDF-file \""+userDefFileName+"\" is already existing. Do you want to overwrite it?",true,undefined);
                                                if (c==0){exit()};  
                                                };
                                            //Error-handling if PDF file override is on and PDF is already opened in an PDF reader app:
                                            try{
                                            d.exportFile(ExportFormat.PDF_TYPE,File(pdfFullName),true,undefined,undefined);
                                            }catch(e){
                                                alert("Error:\r"+e.message+"\r\r(Line "+ e.line+" in script code.)");
                                                exit();
                                                };
                                            

                                             

                                            Uwe

                                            • 19. Re: JS ScriptUI CS4: How to create an indeterminate progress bar?
                                              Vamitul Level 4

                                              i think, based on some tests, that the the problem is the

                                              showingOptions: bool=false

                                               

                                               

                                              exportFile(ExportFormat.PDF_TYPE,expFile,false,app.pdfExportPresets.itemByName("GU"));

                                               

                                              if I change it to true, it shows the progressbar, but also the options dialog, and that, apparentyl, is unacceptable..

                                              • 20. Re: JS ScriptUI CS4: How to create an indeterminate progress bar?
                                                Laubender Adobe Community Professional & MVP

                                                @Vamitul – ah, now I understand…
                                                And you don't want to interrupt the script for user input.

                                                 

                                                So we are back again on square one…

                                                 

                                                Uwe

                                                • 21. Re: JS ScriptUI CS4: How to create an indeterminate progress bar?
                                                  Vamitul Level 4

                                                  no way of using a animated gif or APGN?

                                                  • 22. Re: JS ScriptUI CS4: How to create an indeterminate progress bar?
                                                    Laubender Adobe Community Professional & MVP

                                                    @Vamitul – just another idea:

                                                    could we somehow grab the "percentDone" property of the specific "BackgroundTask" when running the "asynchronousExportFile()" method and use that changing number over time for a progress bar?

                                                     

                                                    Uwe

                                                    • 23. Re: JS ScriptUI CS4: How to create an indeterminate progress bar?
                                                      Vamitul Level 4

                                                      hmm. really nice ideea. also shoud make the export process a bit faster.

                                                      so:

                                                       

                                                      //here is progressbar code by (i think) Peter Kahrel, a bit modified
                                                      var ProgressBar = function ( /*str*/ title)
                                                                {                    var w = new Window('palette', ' ' + title, {
                                                                                    x: 0,
                                                                                    y: 0,
                                                                                    width: 340,
                                                                                    height: 60                    }),
                                                                                    pb = w.add('progressbar', {
                                                                                              x: 20,
                                                                                              y: 12,
                                                                                              width: 300,
                                                                                              height: 12                              }, 0, 100),
                                                                                    st = w.add('statictext', {
                                                                                              x: 10,
                                                                                              y: 36,
                                                                                              width: 320,
                                                                                              height: 20
                                                                                    }, '');
                                                                          st.justify = 'center';
                                                                          w.center();
                                                                          this.reset = function (msg, maxValue)                    {
                                                                                    st.text = msg;
                                                                                    pb.value = 0;
                                                                                    pb.maxvalue = maxValue || 0;
                                                                                    pb.visible = !! maxValue;
                                                                                    w.show();                    };
                                                                          this.hit = function (progress)                    {
                                                                          pb.value=progress;                    };
                                                                          this.hide = function ()                    {
                                                                                    w.hide();                    };
                                                                          this.close = function ()                    {
                                                                                    w.close();                    };
                                                                };
                                                      
                                                      
                                                      var myFolder=Folder(app.activeDocument.filePath).selectDlg("PDF folder:");
                                                      if (myFolder){
                                                                var pBar = new ProgressBar("Export");
                                                      for (var i=0; i<app.documents.length; i++)
                                                      {    myDoc=app.documents[i];
                                                      
                                                      
                                                           expFile = File( myFolder+ '/'+ myDoc.name + '.pdf' );
                                                          var myTask=myDoc.asynchronousExportFile(ExportFormat.PDF_TYPE,expFile,false,app.pdfExportPresets[1]);
                                                          pBar.reset(myDoc.name,100);
                                                          while (myTask.percentDone<100) {
                                                              pBar.hit(myTask.percentDone)
                                                          }
                                                          }
                                                      alert("Done");
                                                      }else{alert("Canceld");}
                                                      
                                                      

                                                       

                                                       

                                                      still no luck. gets stuck in the while loop.

                                                      • 24. Re: JS ScriptUI CS4: How to create an indeterminate progress bar?
                                                        Jim Birkenseer Level 1

                                                        Hi Folks,

                                                         

                                                        Here's what I have discovered. Running the script (below) from within ESTK gives a different behavior than running it from the Scripts Panel from within InDesign. The script below does not work properly (myTask.status never hits completed) when run from within the ESTK; but it DOES work when run from the Scripts Panel. Try it out!

                                                         

                                                        I did not include a progress bar, because I was too lazy! ;-)

                                                         

                                                        var myDoc = app.documents[0];
                                                        var myPreset = app.pdfExportPresets.item(0);
                                                        var myFile = new File("~/Desktop/JUNK_PDF_Test.pdf");
                                                        myTask = myDoc.asynchronousExportFile(ExportFormat.PDF_TYPE,myFile,false,myPreset);
                                                        
                                                        var abortSeconds = 60;
                                                        var seconds = 0;
                                                        while ( myTask.status != TaskState.completed && seconds < abortSeconds)
                                                        {
                                                             $.sleep(1000); // Sleep for one second
                                                             ++seconds;
                                                        } 
                                                        
                                                        if (myTask.status == TaskState.completed)
                                                        {
                                                             alert("myTask.status = Completed   seconds = " + seconds.toString());
                                                        }
                                                        else
                                                        {
                                                             alert("myTask.status = " + myTask.status.toString() + "  seconds = " + seconds.toString());
                                                        }
                                                        
                                                        • 25. Re: JS ScriptUI CS4: How to create an indeterminate progress bar?
                                                          Vamitul Level 4

                                                          nope.. not working for a progressbar.

                                                          yours is probably because you have no ScriptUI panel.

                                                          • 26. Re: JS ScriptUI CS4: How to create an indeterminate progress bar?
                                                            Marc Autret Level 4

                                                            I'm close to a Mac+Win solution (CS4-CS6) that should render an indeterminate progress bar in pure ScriptUI.

                                                             

                                                            My main problem was to make that component work even if the script is invoked from a menu. For some obscure reason, neither the enableRedraw condtion nor the win.update() method seem to allow the progress bar to get properly updated—on MacOS—when the script is triggered by a menuItem/menuAction couple.

                                                             

                                                            However, I cannot pretend that trick will work on any machine. I'll give more details if its effectiveness is confirmed. Give it a try at:

                                                             

                                                            http://www.indiscripts.com/blog/public/scripts/HurryCoverBeta.zip

                                                             

                                                            (For a full test, run the script once from the Scripts panel, then click the Menu icon at the bottom of the dialog to have the script available in a menu. Then, re-run the script from Indiscripts > HurryCover BETA.)

                                                             

                                                             

                                                            Thank you for any feedback.

                                                             

                                                            @+

                                                            Marc

                                                            • 27. Re: JS ScriptUI CS4: How to create an indeterminate progress bar?
                                                              Vamitul Level 4

                                                              hi marc!

                                                              any news in the indeterminate progress bar department?

                                                               

                                                              ps. it seems to work in hurrycovers

                                                              • 28. Re: JS ScriptUI CS4: How to create an indeterminate progress bar?
                                                                myDavey Level 1

                                                                Hello,

                                                                I dont know if this issue is solved yet..... but,

                                                                I created a script that does batch processing (to many files)

                                                                I wanted exactly what was asked for here - a progress bar that shows the progress of the exporting.

                                                                 

                                                                @ Vamitul

                                                                     I was so happy when I saw that code... until I realized that it was getting into an endless loop!!

                                                                     (Only later did I see that you wrote that yourself at the end of the post )

                                                                 

                                                                @ Jim

                                                                     Your script does work somewhat well, but there are 2 problems:

                                                                  1. It doesnt show you the progress of the export
                                                                  2. I never got the "completed" message, so seemingly it was alwyas breaking because of the 60 second interval - which is not so good because every exporting takes different amounts of time.

                                                                 

                                                                I spent a nice amount of time on this tonight... until I gave up!

                                                                Then I tried a little more... and I got it!!!

                                                                I think others can bebefit fromt his as well, so here it is

                                                                 

                                                                // First we run a loop througout the export process.
                                                                // Through watching the finder window during the export,
                                                                // I was able to see that the size if the file does get updated
                                                                // (and task complete) during the scripts hang-up
                                                                // Therefore we can know when to break out of the loop by that condition
                                                                 while (File(newPDFFile).length < 1) {
                                                                     progressBar.value = myTask.percentDone;
                                                                }
                                                                
                                                                // However, it is still not considered a completed task!
                                                                // If we just let the script continue at this point, we will get an error message.
                                                                // So, here we just wait till the task is officially completed and then we are done!
                                                                // This gives us the exact timing - no extra waiting!
                                                                while (myTask.status != TaskState.completed) {
                                                                     myTask.waitForTask();
                                                                }
                                                                

                                                                 

                                                                or, in Vamitul script,

                                                                     replace these lines:

                                                                while (myTask.percentDone<100) {
                                                                     pBar.hit(myTask.percentDone)
                                                                }
                                                                

                                                                 

                                                                     with these lines:

                                                                while (File(expFile).length < 1) {
                                                                     pBar.hit(myTask.percentDone)
                                                                }
                                                                while (myTask.status != TaskState.completed) {
                                                                     myTask.waitForTask();
                                                                }
                                                                

                                                                 

                                                                I tested this in my script and it works great

                                                                I hope it will be of help to others as well!

                                                                 

                                                                ATB

                                                                Davey

                                                                • 29. Re: JS ScriptUI CS4: How to create an indeterminate progress bar?
                                                                  Laubender Adobe Community Professional & MVP

                                                                  @Davey – thank you for sharing this. The problem was pending. At least for me ;-)

                                                                   

                                                                  Now, I tested with a slightly altered version of the code from Vamitul (answer #23 here) – not exporting all InDesign files of a folder to PDF, but a selection of files from a folder – using your while loops instead the one by Vamitul.

                                                                   

                                                                  I can only say:

                                                                  it's working well.

                                                                  Thank you!!

                                                                   

                                                                  Uwe

                                                                  • 30. Re: JS ScriptUI CS4: How to create an indeterminate progress bar?
                                                                    myDavey Level 1

                                                                    Hi Uwe

                                                                    Thanks for the confirmation!

                                                                     

                                                                    I just realized that we dont really need to have the second part in a while loop

                                                                    Technically it can be a stand alone code right outside the first loop:

                                                                     while (File(newPDFFile).length < 1) {
                                                                         progressBar.value = myTask.percentDone;
                                                                    }
                                                                    
                                                                       myTask.waitForTask();
                                                                    
                                                                    

                                                                     

                                                                    and it will work the same way.

                                                                    However, its probably better to put it in an if statement, just in case it is already complete:

                                                                     while (File(newPDFFile).length < 1) {
                                                                         progressBar.value = myTask.percentDone;
                                                                    }
                                                                    
                                                                    if (myTask.status != TaskState.completed) {myTask.waitForTask()}
                                                                    

                                                                     

                                                                     

                                                                    Davey

                                                                    • 31. Re: JS ScriptUI CS4: How to create an indeterminate progress bar?
                                                                      Laubender Adobe Community Professional & MVP

                                                                      @Davey – thank you again…

                                                                       

                                                                      I'm not so sure, if "myTask" can be ever completed after the while loop.
                                                                      So I think, the if statement will at least do no harm. ;-)

                                                                       

                                                                      Sorry, no time right before Christmas doing a lot of tests.

                                                                       

                                                                      Uwe