Skip to main content
Known Participant
October 12, 2023
Question

Scripting a Progress Bar only works if total time is < 5 Seconds

  • October 12, 2023
  • 1 reply
  • 200 views

Hi everybody
I am trying to write a simple progress bar script, to use in my other scripts.

// Function to update the progress bar
function updateProgressBar(value, max) {
    var progressBarWindow = new Window("palette", "Progress", undefined);
    var progressBar = progressBarWindow.add("progressbar", undefined, 0, max);
    progressBarWindow.show();
    progressBarWindow.center();
    // Function to update the progress value
    progressBarWindow.updateProgress = function (value) {
        progressBar.value = value;
        this.update();
    };
    return progressBarWindow;
}

// Example usage:

var progressBar = updateProgressBar(0, 100); // Create a progress bar with a maximum value of 100
var startTime = new Date().getTime(); // Get the current time
var duration = 6000; // 5 seconds in milliseconds

while (new Date().getTime() - startTime < duration) {
    // Update the progress bar value based on the elapsed time
    var elapsed = new Date().getTime() - startTime;
    var progress = (elapsed / duration) * 100;
    progressBar.updateProgress(progress);
}
// Close the progress bar window when done
progressBar.close();

this works totally fine for
var duration = 5344
for
var duration = 5345
or more, the script hangs and the progress bar doesn’t close, and is not closeable by hand afterwards.

The same behavior happend when i tried to use in a script which looks in a bunch of layers. If the total time the script needs is under 5 seconds everything works fine, if it needs longer it hangs.

Any ideas on that really strange behavior? I tested on two different computers.
Did somebody have implemented a progress bar in a script and tested if it works fine for longer durations than 5 or 6 seconds? Would be really helpful to know what you did different.

 

1 reply

August 12, 2025

Hey arnem,

 

1) "progress bar doesn’t close":

I recently discovered that calling new Date() while the progress bar is open will cause the window not to close. Using $.hiresTimer instead of new Date() hasn't worked for me either. I'm still looking into it but at the moment I'm personally forgoing the "Estimated Time Remaining"

 

2) "only works if total time is < 5 Seconds":

From what I understand, this is a common problem with the AE Scripting progress bar. I would suggest being mindful of the tasks you're automating while the progress bar window is up and to do some of the more interaction-based automations before and after the progress bar.

 

Mike