Skip to main content
Inspiring
August 16, 2023
Question

Spinning wheel prevents mouse input to cancel script (SUI)

  • August 16, 2023
  • 3 replies
  • 1420 views

Hello,

 

I've written a script that exports all documents from a selected folder as PDFs. I've added a progress bar that also has a Cancel button. However, while ID is exporting the PDFs it shows the spinning wheel the entire time, so I can't hit the cancel button to stop the script from progressing, it always processes all documents until the end.

 

Is this is common behaviour? I've tried adding $.sleep(500) and rapidly hit the cancel button to no avail.

 

Thanks,
Frank

This topic has been closed for replies.

3 replies

Peter Kahrel
Community Expert
Community Expert
August 21, 2023

I don't know about the spinning wheel, I don't see that on my Windows PC. Do you use a Mac?

 

For the cancel button, your code still works its way through the whole file array, it just doesn't do anything. Maybe change the cacel burron's function like this:

 

buttonp.onClick = function() {
  // Close all documents, then
  exit();
}

 

 

By the way, it looks as if there's a bug in asynchronousExportFile(). When you use it, document.close() returns an error. The error disappears when you use the synchronous exportFile(). The latter works fine, your script runs ok over here (with exportFile()).

 

On another note, like Loic I was surprised at your forEachDescendantFile() function. As I understand it, you open, export, and close each document inside a recursive function. That looks overwrought to me, and may explain why you run into difficulties that require your Monty Pythonesque error message ""The object at . . . is a child of a folder and yet is not a file or folder."

 

To find files in a folder and its subfolders and process them, this seems much simpler:

 

function findIndd (f, list) {
  var f = Folder(f).getFiles('*.*');
  for (var i = 0; i < f.length; i++) {
    if (f[i] instanceof Folder) {
      findIndd (f[i], list);
    } else if (/\.indd$/i.test (f[i].name)) {
      list.push (f[i]);
    }
  }
  return list;
}


indds = findIndd (myFolder, []);
for (i = 0; i < indds.length; i++) {
  // process file
}

 

 Just a thought. . .

Inspiring
August 21, 2023

Hi Peter,

Thanks for your input.

Yes, I'm using a Mac and whenever the system is more busy than usual the cursor changes into a spinning rainbow circle. While the spinning wheel is visible, the system usually doesn't recognise any button inputs. I'll try the exit() method that you suggested, but I think that cancel function won't be triggered.

As for the overly complicated find-files-in-a-folder process, yes, that was a template that I was using before I understood that I could be done much simpler (like your code snippet suggests). I've used your suggestion in many other smaller scripts, but now that you confirmed the long version is unnecessary, I should really get rid of it. Thanks!

Inspiring
August 16, 2023

Thanks for your reply. I changed to the asynchronous method but the Cancel button is still not clickable.

Inspiring
August 17, 2023

The window type is already palette, but good thinking.

Inspiring
August 19, 2023

Nice, thanks so much for your help. I'll try it out tomorrow and let you know if that solution works for me. But it all makes sense, so I'm hopefull! Thank again.


Alright, so I have tested your script and it worked fine. I applied the same basic rules to my script, and the wheel kept spinning without even processing the first file… I used // @targetengine "session" in your sample but not in my script, could that be the problem? My scripts runs in main().

The changes to my script were:

- changed from exportFile to asynchronousExportFile

- saving each background task t in object tasks

- if cancel button is cliked, cancel the task and delete it from the object

 

My script runs through all documents in a previously selected folder (and sub-folder) and exports each one by one. In theory, it should work…

 

Loic.Aigon
Legend
August 16, 2023

By default yes if you do export syncronously where you basically freeze the app (it's a modal process). If you use asynchronousExportFile You will have exports done in the background with the app non frozen (non modal). This will create background tasks that you can possibly monitor and "possibly" stop processes  (tbh I am not completely sure but that's where I would investigate).