3

应该比较简单。在为 Adob​​e InDesign CS6 编写脚本时,我想让一个窗口/调色板短暂出现(比如大约两秒钟),以通知用户脚本已成功到达末尾。我该怎么做呢?

4

2 回答 2

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;
}
于 2013-06-19T06:55:55.427 回答
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 个。在 main 函数的末尾,我删除了一个简单的progress.parent.close();行。最后,main 函数之后,我在函数中删除了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!

于 2013-06-19T15:56:10.683 回答