Skip to main content
March 16, 2009
Question

[AS] Script runs slower and slower

  • March 16, 2009
  • 23 replies
  • 3847 views
I am working on some scripts which interacts a lot with each page of a long InDesign document - basically it does a lot of searching, and does stuff depending on what it finds.

For the first couple of minutes, its really fast, but then gets slower and slower.

Is there any way to make InDesign catch its breath? Like pausing the script?
This topic has been closed for replies.

23 replies

Inspiring
March 17, 2009
I'm not sure that turning redraw off did anything in CS3; I haven't checked<br />in CS4.<br /><br />I did a rough test with a script that had to draw several hundred<br />transparent ovals. To make it go faster, the script made the layer they were<br />on invisible, so no redraw was needed. Even so, it took maybe 3-4 minutes;<br />doing it without a window took closer to half-a-minute.<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au><br />AppleScript Pro Sessions <a href=http://scriptingmatters.com/aspro>
Known Participant
March 17, 2009
Hi Thomas,

Here's a general purpose "do script" script--it'll just run a script file you select using the "fast entire script" undo mode:

--RunScriptFromFile.applescript

--An InDesign CS4 AppleScript
--
--Runs a script file using the do script method.
set myScriptFile to choose file with prompt "Select an AppleScript"
tell application "Adobe InDesign CS4"
do script myScriptFile language applescript language undo mode fast entire script undo name (myScriptFile as string)
end tell

Should be quite a bit faster. Let me know how it works for you!

Thanks,

Ole
November 24, 2009

What is the difference between "fast entire script" and "entire script" ?

I noticed the "fast" doesn't seem to work properly in one of my scripts, the script executes, but it won't replace the contents of a text frame...

From documentation:

--undo modes can be:

--auto unto: Add no events to the Undo queue.

--entire script: Put a single event in the Undo queue.

--fast entire script: Put a single event in the Undo queue.

--script request: Undo each script action as a separate event.

--The last parameter is the text that appears in the Undo menu item.

test code:

on run

set theScriptFile to choose file with prompt "Select an AppleScript to run:"

tell application "Adobe InDesign CS4"

do script theScriptFile language applescript language undo mode fast entire script undo name ("Undo test" as string)

end tell

end run

Snippet of code that should work from theScriptFile, but doesn't follows:

tell application "Adobe InDesign CS4"

set (contents of parent story of textFrameRef) to "replace with new text"

end tell

--FYI: textFrameRef  = text frame id 11290 of page id 6618 of spread id 6605 of document "myTestDocument.indd" of application "Adobe InDesign CS4"

Inspiring
November 24, 2009

> I noticed the "fast" doesn't seem to work properly in one of my scripts, the script executes, but it won't replace the contents of a text frame...

FWIW, I've seen the some thing; I just use entire. It doesn't seem to make much difference time-wise.

March 17, 2009
Would it be the same result as turning redraw off?
Inspiring
March 17, 2009
The other potential speed booster is to open the document you're working on<br />without a window. just make sure you handle any potential errors.<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au><br />AppleScript Pro Sessions <a href=http://scriptingmatters.com/aspro>
March 17, 2009
Thanks for the latest tips as well!

Olav: I am yet to experiment with the do script feature, sounds exciting and may speed things up further.

I have launched a new InDesign blog where my latest post shows what I accomplished with this script. And I must say, executing a script from the scripting palette in InDesign makes scripts run waaay faster than from the AppleScript editor. What took an hour to run through now is done in minutes.

Blog post and video can be seen at http://indesigning.net/the-power-of-scripting
Known Participant
March 17, 2009
Hi Thomas,

In InDesign CS4, you can also run your script using the do script method--if you do that, you can turn off undo altogether (or, really, package all of the script actions as a single undo step).

Thanks,

Ole
Known Participant
March 17, 2009
Without seeing your code it's hard to say what you can optimize. Repeat loops are your first area to target, to make them as fast as possible. There are some very tricky ways to deal with lists in repeats that can yeild amazing results, but need to be studied carefully. Check MacScripter.net for examples. You might also want to try to limit the size of any lists, or try to filter down a list of objects to a shorter list of objects. Or instead of looking at all page items only look at page items of page X.
March 17, 2009
I fired the script from the script palette in InDesign instead, helped a lot ;)
March 17, 2009
I can feel a clear difference from before to now, but still the script runs a little slower and slower. Do you know of any other ways of optimizing?
March 17, 2009
Thanks, fixed it.. Found out that "file path" didn't include the document name, "full name" did.

Thanks!