basiljs/basil.js

UI button in InDesign to cancel running script

ffd8 opened this issue · 1 comments

ffd8 commented

This is a feature request/idea – since we are moving away from ESTK to just Sublime, there's often a problem of accidently running a script that could go on for ever.. changing a for loop from 10 to 100 and waaaaiting. With ESTK there was the great 🛑 button, but with Sublime - not sure of how to cancel a running script besides force quiting InDesign. Unless there's an obvious key to press:

what about a UI box that floats on top of InDesign with minimal basil.js info + 🛑 button, that could somehow call an exit() or equivalent code? Tried researching indesign scripting stop/abort/cancel script – but most results point to ESTK button.. curious what official VSCode answer is (if it has one). The UI popup would appear and dissapear upon load/finish automatically.

ffd8 commented

Tested aborting a script – ie. accidental infinite loops or characters on a HUGE text.. or anything else that could accidently take too long. Found the following code to abort:
while (ScriptUI.environment.keyboardState.keyName == "Escape"){exit()}

Unfortunately, when simply placed once in the script, it doesn't work for loops. However if placed within a loop, makes it possible to abort at any time before it's finished:

  for(var i=0; i < 150; i++){
  	while (ScriptUI.environment.keyboardState.keyName == "Escape"){exit()}
  	fill(random(255));
  	rect(random(width), random(height), random(1, 50), random(1, 50));
  }

Guessing there's no preparser for JS within InDesign to try and inject such a line on all loops?
Maybe it's worth making a basic alias for that line, something like safety() or breaker() or ______?
And encourage students to include that if concerned about being able to abort a script?