Skip to main content
Cefalopodo
Inspiring
October 31, 2023
Question

Stop Script execution from CEP panel.

  • October 31, 2023
  • 3 replies
  • 689 views

Is there a way to force an script to stop executing from CEP panel?  For example in long loops:

my first thought was to make the loop in the CEP context and pass the index and the data in each loop to an extendscript method, so I can control the loop outside, but it seems to be a little cumbersome.

 

Is there a simpler aproach?  I'm especially thinking about more complex processes with more loops and complexity layers

 

This topic has been closed for replies.

3 replies

Hey Evgenii
Inspiring
March 15, 2024

Maybe not the best approach, but the way I managed to make it work is by creating stop.txt file next to the main extendscript file and when user runs functions from UI, it writes with fs and path modules to the txt file '0' which means 'don't stop', the through extendscript I added checkers that read the file and throw error if the stop.txt contains '1', error is taken care by trycatch
stop button in UI writes to stop.txt '1' which means 'stop'

Alex White
Legend
October 31, 2023

You can make your function run async with "app.scheduleTask();"  and during each loop check the global object if the execution should continue, for example:

 

if ($.["myscriptname"].continueRun === false) {
  // break the loop here and cancel task
  app.cancelTask(); //
}

 

Cefalopodo
Inspiring
October 31, 2023
It seems like an interesting approach. I'm going to give it a try and tell you if that worked. Thanks

 

Mathias Moehl
Community Expert
Community Expert
October 31, 2023

I don't think this is possible, unfortunately.
As you suggested, the only option is probably to do the loop in CEP and split the job into many small jsx executions. That's also what I do in Still Exporter, for example, to show a status update in the CEP panel while the images are exported.

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Cefalopodo
Inspiring
October 31, 2023
I was also just thinking about it to make progress bars, although perhaps for that it would be easier to use the extendscript UI builtin tools.