Domanda

This should be relatively simple. While writing a script for Adobe InDesign CS6, I'd like to have a window/palette appear briefly—say, about two seconds— to notify the user that the end of the script was reached successfully. How can I go about doing this?

È stato utile?

Soluzione

try this:

main();
function main(){
      var progress_win = new Window ("palette");
var progress = progress_bar(progress_win, 2, 'Doing Something. Please be patient');
    delay(1);
      progress.value = progress.value+1;
    delay(1);
    progress.parent.close();
    }

// delay function found here
//found here http://www.wer-weiss-was.de/theme157/article1143593.html
  function delay(prmSec){
  prmSec *= 1000;
  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);
var pbar = w.add ("progressbar", undefined, 1, stop);
pbar.preferredSize = [300,20];
w.show ();
return pbar;
}

Altri suggerimenti

Your answer provided me with an idea for my script: instead of just having a pop-up that says "I'm done!", show a progress bar! So, using the ScriptUI for dummies document, I was able to come up with the following code for the beginning of the script:

// Creating a progress bar window.
var w = new Window("palette");
var progress = progress_bar(w, 27);
var currentDoc = w.add("statictext");
currentDoc.text = "Processing " + document.name;
w.show();

Then, throughout the script, peppering it with progress.value += 1; statements (usually whenever a single process has been completed), which totaled 27. At the end of the main function, I dropped a simple progress.parent.close(); line. Finally, after the main function, I dropped in the progress_bar() function:

/**
 * Creates the actual progress bar object
 *
 * @param {Palette} w The pallette the progress is shown on
 * @param {number} stop The value which represents 100% of the progress bar
 */
function progress_bar(w, stop) {
    var pbar = w.add("progressbar", undefined, 1, stop);
    pbar.preferredSize = [300, 20];
    return pbar;
}

And that seems to do it! The progress bar appears, crawls to the end while it processes the file, then once the progress bar closes, the script is done! Thanks for pointing me in a much better direction, fabiantheblind!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top