简体   繁体   English

Javascript/ExtendScript/ScriptUI 临时窗口消息

[英]Javascript/ExtendScript/ScriptUI temporary window message

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.在为 Adob​​e InDesign CS6 编写脚本时,我希望短暂出现一个窗口/调色板(比如大约两秒钟),以通知用户脚本已成功到达结尾。 How can I go about doing this?我该怎么做呢?

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 come up with the following code for the beginning of the script:因此,使用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();

Then, throughout the script, peppering it with progress.value += 1;然后,在整个脚本中,使用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();语句(通常在单个进程完成时),总共 27 个。在 main 函数的末尾,我删除了一个简单的progress.parent.close(); line.线。 Finally, after the main function, I dropped in the progress_bar() function:最后,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;
}

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!谢谢你给我指明了一个更好的方向,fabiantheblind!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM