Progress And Delay - ff6347/extendscript GitHub Wiki
This is a simple script that demonstrates how to use progress bars and have some delay with that. Originally assembled for this stackoverflow.
main(); // main function everything happens in here
function main(){
var progress_win = new Window ("palette"); // create new palette
var progress = progress_bar(progress_win, 2, 'Doing Something. Please be patient'); // call the pbar function
delay(1); // wait a second
progress.value = progress.value+1; // update the progress bar
delay(1); // wait another second
progress.parent.close(); // close the palette
return 0; // we are done
}
// delay function found here
//found here http://www.wer-weiss-was.de/theme157/article1143593.html
function delay(prmSec){
prmSec *= 1000; // Dates work in milliseconds
var eDate = null;
var eMsec = 0;
var sDate = new Date();
var sMsec = sDate.getTime();
do {
eDate = new Date();
eMsec = eDate.getTime();
} while ((eMsec-sMsec)<prmSec);
}
/**
* Taken from ScriptUI by Peter Kahrel
*
* @param {Palette} w the palette the progress is shown on
* @param {[type]} stop [description]
* @return {[type]} [description]
*/
function progress_bar (w, stop, labeltext) {
var txt = w.add('statictext',undefined,labeltext); // add some text to the window
var pbar = w.add ("progressbar", undefined, 1, stop);// add the bar
pbar.preferredSize = [300,20];// set the size
w.show ();// show it
return pbar; // return it for further use
}