how to know illustrator script ends?

Community Beginner ,
Feb 09, 2022 Feb 09, 2022

Copy link to clipboard

Copied

Run a script from command line:

"c:\program files\full path to your illustrator version\illustrator.exe" "c:\full path to your script\script.jsx"

I have found that the command will not block and the task continued, so is there any way to block the script before the task ends?

TOPICS
Performance , Scripting , SDK , Sync and storage

Views

65

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 10, 2022 Feb 10, 2022

Copy link to clipboard

Copied

Hello, I don't understand your question. Can you please describe it more precisely?

If you only want the javascript to wait for a fixed time, then this can help you:

 

$.sleep(1000); // tell extendscript to sleep 1000 milliseconds
// your code will be executed after 1 second
alert("hello one");

// setTimeout of normal Javascript, but not part of extendscript
$.setTimeout = function(func, time) {
  $.sleep(time);
  func();
};
$.setTimeout(function () {alert("hello world")}, 1000);

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 10, 2022 Feb 10, 2022

Copy link to clipboard

Copied

LATEST

In order to block, an Illustrator script must be sent from ESTK which forces a targetengine, or to find a way to force a targetengine because when running as normal, Illustrator runs scripts inside the targetengine which is an empty string.
You can check by $.engineName == "";
However, you can send your script through with BridgeTalk which is how you can force an targetengine.

if ($.engineName == "") {
  var scriptContents;
  var scriptFile = File($.fileName);
 
  var bt = new BridgeTalk();
  bt.target = "illustrator";
  var btMsg = '#targetengine "main"\n';
  btMsg += 'var scp = "' +
  encodeURI(
    "$.evalFile('" + decodeURI(scriptFile.toString()) + "')"
  ) + '";\n';
  btMsg += "var scpDecoded = decodeURI( scp );\n";
  btMsg += "res = eval( scpDecoded );";
  bt.body = btMsg;

  bt.onResult = bt.onError = function () {
    resultFinished = true;
  }
  bt.send();
  var timeoutMinutes = 5;
  var timeout = timeoutMinutes * 60;
  for (var i = 0; i < timeout; i++) {
      BridgeTalk.pump();       // process any outstanding messages
      if (!resultFinished) {
          $.sleep(1000);
      } else {
          break;
      }
  }
}
 
As you see, using $.sleep to wait for a BT result out of a script that has an empty-string targetengine is supposedly going to block the process based on a specified timeout. The bad news is that while there's no issue exiting early, after the timeout is up, the process will unblock. However, between calls to BridgeTalk.pump() (thanks to Fabian Zirfas BT sendSync prototype, it's somewhere) the script can be also reading the filesystem for a text file or some marker to detect completion and potentially leaving the timeout open indefinitely.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines