最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

JavascriptExtendScriptScriptUI temporary window message - Stack Overflow

programmeradmin2浏览0评论

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?

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?

Share Improve this question edited Jan 19, 2020 at 14:45 RobC 25.1k21 gold badges84 silver badges86 bronze badges asked Jun 18, 2013 at 17:35 SturmSturm 7792 gold badges28 silver badges57 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

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;
}

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 e 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 pleted), 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!

发布评论

评论列表(0)

  1. 暂无评论