2 Replies Latest reply on Mar 23, 2016 7:40 AM by CarlosCanto

    A Batch-Action Progress Bar script.

    Silly-V Adobe Community Professional

      It is finally here, the one we have all been waiting for! The time is now upon us, to test out this progress bar script!

      Ever done batch actions and wanted to ask "How far along am in in this batch anyway?".

      So now you must ask no more, the answer is now provided here, a pop-up progress bar that stays on screen a few milliseconds and shows how far along you are in this batch of files.

      It uses consideration of any file not starting with (.) dot in the parent folder of the current file (if the active document is untitled as in 'new', then the script does nothing), and counts the current file's index in the folder by comparing its name.

       

      function pbar(){
        function ProgressPalette(max, msg){
         var obj = {}, msg = (msg || "");
         var w = new Window("palette", "Your Progress:", undefined, {closeButton:false});
         var p = w.add('progressbar'); p.size = [300, 20];
         p.maxvalue = max;
         var s = w.add("statictext", undefined, msg);
         var e = w.add('edittext', undefined, '0 of ' + max);
         e.characters = 20;
         e.justify = 'center';
         obj.show = function(){w.show();};
         obj.close = function(){w.close();};
         obj.update = function(){w.update();};
         obj.setValue = function(val){
           p.value = val;
           e.text = val + " of " + p.maxvalue;
           this.update();
         };
         return obj;
        };
        if(app.documents.length == 0){
        return;
        }
        var thisDocPath = decodeURI(app.activeDocument.fullName);
        var len = thisDocPath.length;
        if(len - thisDocPath.replace(/[\/\\]+/g, '').length < 1){
        return;
        }
      
        var thisFile = File(thisDocPath);
        var thisFolder = thisFile.parent;
        var allFiles = thisFolder.getFiles(function(f){
        return f instanceof File && f.displayName.toString().charAt(0) != ".";
        });
        var allFilesNum = allFiles.length;
        var index;
        for (var i = 0; i < allFiles.length; i++) {
        if(allFiles[i].displayName == app.activeDocument.name){
        index = allFiles.length - (i);
        break;
        }
        }
        if(typeof index == "undefined"){
        alert("index never found!");
        return;
        }
        var p = new ProgressPalette(allFilesNum, "Document: '" + app.activeDocument.name + "'");
        p.show();
        p.setValue(index);
        $.sleep(500);
        p.close();
      }
      pbar();
      
      

       

      Who can test this, are you brave enough to be part of the new paradigm? Join me on the information superhighway, my friends!

        • 1. Re: A Batch-Action Progress Bar script.
          Silly-V Adobe Community Professional

          A more in-depth one here:

           

          function pbar(){
          
          
            function BatchProgressPalette(msg){
            var bpp = this;
            if(typeof msg != "undefined"){
            this.msg = msg;
            }
            this.setUIValues = function(win, desc, pbar, disp, val, msg){
               pbar.value = val;
               disp.text = val + " of " + pbar.maxvalue;
               desc.text = msg;
               win.update();
            };
            this.UIWindow = function(max, msg, closeButton){
             var obj = {}, msg = (msg || "");
             var w = new Window("palette", "Your Progress:", undefined, {closeButton:(closeButton || false)});
          
          
             var s = w.add("edittext", undefined, msg, {multiline : true});
              s.size = [300, 42];
          
          
             var p = w.add('progressbar'); p.size = [300, 20];
             p.maxvalue = max;
          
          
             var e = w.add('edittext', undefined, '0 of ' + max);
             e.characters = 20;
             e.justify = 'center';
             obj.desc = s;
             obj.pbar = p;
             obj.disp = e;
             obj.show = function(){w.show();};
             obj.close = function(){w.close();};
             obj.update = function(){w.update();};
             obj.setValue = this.setUIValues;
             return obj;
            };
            this.batch_dataSets = {
            main : function(){
            var doc = app.activeDocument, index, dsCount, dsName, msg;
            dsCount = doc.dataSets.length;
            if(dsCount < 1){
            return;
            }
            dsName = doc.activeDataSet.name;
            index = this.getIndex(dsName, doc);
            if(typeof bpp.msg == "undefined"){
            msg = "Document: '" + app.activeDocument.name + "'" + "\nData Set: '" + dsName + "'";
            } else {
            msg = bpp.msg;
            }
            bpp.displayBar(dsCount, index, msg);
            },
            getIndex : function(dsName, doc){
            var index;
            for (var i = 0; i < doc.dataSets.length; i++) {
            if(doc.dataSets[i].name == dsName){
            index = (i + 1);
            break;
            }
            }
            return index;
            }
            };
            this.batch_files = {
            main : function(){
            var doc = app.activeDocument, msg;
            var thisDocPath = decodeURI(doc.fullName);
            var len = thisDocPath.length;
            if(len - thisDocPath.replace(/[\/\\]+/g, '').length < 1){
            return;
            }
            var thisFile = File(thisDocPath);
            var thisFolder = thisFile.parent;
            var allFiles = thisFolder.getFiles(function(f){
            return f instanceof File && f.displayName.toString().charAt(0) != ".";
            });
            var allFilesNum = allFiles.length;
            var index = this.getIndex(allFiles, doc);
            if(typeof bpp.msg == "undefined"){
            msg = "Document: '" + app.activeDocument.name + "'";
            } else {
            msg = bpp.msg;
            }
            bpp.displayBar(allFilesNum, index, msg);
            },
            getIndex : function(allFiles, doc){
            var index;
            for (var i = 0; i < allFiles.length; i++) {
            if(allFiles[i].displayName == doc.name){
            index = allFiles.length - (i);
            break;
            }
            }
            if(typeof index == "undefined"){
            alert("index never found!");
            return;
            }
            return index;
            }
            };
            this.displayBar = function(max, index, msg){
            var myW = Window.find("palette", "Your Progress:");
            if(myW){
            if(!myW.visible){
            myW.show();
            }
            myW.children[1].maxvalue = max;
            this.setUIValues(myW, myW.children[0], myW.children[1], myW.children[2], index, msg);
            if(index == max){
            myW.close();
            }
            } else {
            var p = bpp.UIWindow(max, msg, true);
             p.show();
             p.pbar.maxvalue = max;
             p.setValue(p, p.desc, p.pbar, p.disp, index, msg);
            if(index == max){
            p.close();
            }
            }
            };
            this.init = function(files_dataSets){
            if(app.documents.length == 0){
            return;
            }
            this["batch_" + files_dataSets].main();
            };
            };
          
          
            var batchPbar = new BatchProgressPalette();
          
            batchPbar.init("files");
            // batchPbar.init("dataSets");
          
          
          }
          pbar();
          
          • 2. Re: A Batch-Action Progress Bar script.
            CarlosCanto Adobe Community Professional & MVP

            good!! the previous script wasn't deep enough