Javascript / ExtendScript / ScriptUI临时窗口消息

问题描述 投票:3回答:2

应该相对简单。在为Adobe InDesign CS6编写脚本时,我希望让窗口/调色板短暂出现(例如大约两秒钟),以通知用户脚本的结尾已成功到达。我该怎么做?

javascript window extendscript palette adobe-scriptui
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;
}

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();行。最后,在[[after主函数中,我加入了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!
© www.soinside.com 2019 - 2024. All rights reserved.