Hi
I’ve been trying to avoid doing this, but I’m kind of at my wits end. I’ve written a script that goes through an InDesign document and plants codes around elements that get lost on export to EPUB format. It works, but it can be slow. Unfortunately, that has finally caught up with me. I am trying to run it on a 580-page file with literally tens of thousands of elements for it to tag, and it’s taking much longer than I think it should.
I have been running it from a handler so that I could set the undo mode to “fast entire script” (I had it at “auto” with no real difference in performance). I set the time out to 500,000 seconds; after about 21 hours, Applescript did time out.
I tried running it without the handler so I could watch the replies, and I noted that as it worked, it got progressively slower.
I’m pasting the code in the hopes that someone can give me tips on how to make it run at a reasonable speed.
FYI, I’m new to Applescript, but I’ve been working with complex VBA scripts for many years.
tell application "Adobe InDesign CS4"
set typographers quotes of text preferences to false
repeat with myDocumentsCounter from 1 to count documents
set myDocument to document myDocumentsCounter
--Insert "<a>" tag at the beginning of each page
repeat with myPageCounter from (count of pages in myDocument) to 1 by -1
set myPage to page myPageCounter of myDocument
repeat with myTextframeCounter from 1 to (count of text frames in myPage)
set myTextframe to text frame myTextframeCounter in myPage
if (count of characters in myTextframe) is greater than 0 then
if next text frame of myTextframe is not equal to nothing or previous text frame of myTextframe is not equal to nothing then
tell myTextframe
set beginning to "<a id=\"p" & name of myPage & "\"/>"
end tell
end if
end if
end repeat
end repeat
--Find text that deviates from its paragraph definition in specific ways and flag that text
set find grep preferences to nothing
set change grep preferences to nothing
repeat with myStoriesCounter from 1 to count stories in myDocument
set myStory to story myStoriesCounter in myDocument
if (count of characters of myStory) > 0 then --ignore empty text columns
if class of parent of parent of item 1 of parent text frames of text column 1 of myStory is spread then --ignore master spreads
if (count of text style ranges in myStory) > 1 then --ignore stories with no changes from defined text style
repeat with myTextStyleRangesCounter from (count of text style ranges in myStory) to 1 by -1
set myTextStyleRange to object reference of text style range myTextStyleRangesCounter in myStory
if font style of myTextStyleRange is not font style of applied paragraph style of myTextStyleRange then --and font style of myTextStyleRange is not font style of applied character style of myTextStyleRange then
set myFontStyle to "<~" & font style of myTextStyleRange & "~>"
tell myTextStyleRange
set {end, beginning} to {"<~~>", "<~" & font style of myTextStyleRange & "~>"}
clear overrides
end tell
end if
end repeat
end if
end if
end if
end repeat
--Find/Change with hex codes those characters that will get lost on export but that need to be retained
set find grep preferences to nothing
set change grep preferences to nothing
set myFindList to {"(\\r)(\\r)", "~m", "~>", "~/", "~f", "~s", "~S", "~.", "~4", "~y", "~%", "~<", "~#"}
set myChangeList to {"$1 $2", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}
repeat with myFindListCounter from 1 to count myFindList
set find what of find grep preferences to item myFindListCounter of myFindList
set change to of change grep preferences to item myFindListCounter of myChangeList
tell myDocument
change grep
end tell
end repeat
end repeat
set typographers quotes of text preferences to true
display dialog ("All done!")
end tell
The script seems to be having trouble in the section, “–Find text that deviates from its paragraph definition in specific ways and flag that text”
Thanks for any thoughts.
Browser: Safari 536.26.14
Operating System: Mac OS X (10.8)