Javascript / ExtendScript / ScriptUI临时窗口消息

时间:2013-06-18 17:35:30

标签: javascript time window extendscript palette

这个应该相对简单。在为Adobe InDesign CS6编写脚本时,我想让一个窗口/调色板短暂出现 - 比如大约两秒钟 - 来通知用户脚本的结束已成功到达。我怎么能这样做呢?

2 个答案:

答案 0 :(得分:4)

试试这个:

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

答案 1 :(得分:4)

您的回答为我提供了一个关于我的脚本的想法:而不是只是弹出一个“我已经完成!”的弹出窗口,显示进度条!因此,使用ScriptUI for dummies document,我能够为脚本的开头提出以下代码:

// 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();

然后,在整个脚本中,使用progress.value += 1;语句(通常在单个进程完成时),总计为27个。在主函数结束时,我删除了一个简单的progress.parent.close();线。最后,主函数之后,我放入了progress_bar()函数:

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

这似乎就是这样!出现进度条,在处理文件时爬行到最后,然后一旦进度条关闭,脚本就完成了!感谢你指点我更好的方向,fabiantheblind!