How to select last processed item from the loop

Hi all,

I’m pretty new to whole Applescripting and I’m rather compiling my script from bits and pieces of other people’s work then writing my own stuff (yet…). Basically I’m looking for solutions that would help me and my teammates with everyday work which is localisation of a hell lot of printed content.

I recently found a great piece of scripting ErrorCheckInDesign 1.1 (http://scriptbuilders.net/files/errorcheckindesign1.1.html) but would like to make some rework to more suit my needs. Inside, there’s a piece of code that check the document for overflowing text:


set theCount to count of story of theDoc
		repeat with i from 1 to theCount
			set theFrame to story i of theDoc as reference
			set theProps to properties of story i
			if overflows of theProps is true then
				set textProb to display dialog "This document contains Text Overflow. Please check all text boxes. Script can not continue until this is corrected" buttons {"OK"} default button 1
				if button returned of textProb is "OK" then select last item of story
			else
				delay 1
			end if
		end repeat

What I would like it to work like, is to select the last selected piece in the loop of checking. This would select the overflowing piece and the designer would be able to work on the exact textbox without going through all document. Unfortunately my knowledge of the language doesn’t allow me to make it work… Any ideas how this could be solved?

Cheers
Radek

Model: G5 1.8 dual
AppleScript: 1.10.7
Browser: Firefox 2.0.0.9
Operating System: Mac OS X (10.5)

I don’t use inDesign so I don’t know how to select the text box corresponding to story i, but since there may well be more than one overflowing, the usual approach would be to make a list of the i values at which overflow was true and then outside the detection loop revisit them in a new loop. That way you don’t have to run the entire test again to see if there are others than the “last” one. Knowing nothing about inDesign, I can’t give an example.

Sounds as if you need to save the numbers of the stories in an array:

at the beginning, set storyList to {}

then each time it finds a story that is overflowed,

set end of storyList to i

And remove the display dialog line.

Then at the end of the script put a Display Dialog that says

display dialog “The following stories were overflowed:” & storyList

I don’t have InDesign so can’t test this but that would give you a list of stories.

If the Properties has the name of the story, you could somehow use that also in the list.

Thanks Johnny & Adam,

Johnny:
The issue is that the document may have let’s say 20 stories, which do not have names or labels, so it would be hard to locate the proper story. That’s why I’d rather have the script stopping and then selecting the overflowing text box automatically…

Hi

I’ve only just glanced at your problem and this is by no means a solution!!
However i can’t see away of selecting what you want via the story you will have to isolate the text frame
someway, but i think it can be done!!
in the meantime you could do this or even use this to further your ideas on how to get the result your after.
i haven’t the time at the minute to do much more work is busy!!
This will highlight the text thats overflowing in a swatch color.

tell application "Adobe InDesign CS3"
	set theDoc to the front document
	tell theDoc
		-- check for text overflow
		set theCount to count of story of theDoc
		repeat with i from 1 to theCount
			set theFrame to story i of theDoc as reference
			set theProps to properties of story i
			if overflows of theProps is true then
				set fill color of theFrame to swatch 5 --pick what ever you want here or create your own!!
			end if
		end repeat
	end tell
end tell

if i get chance i will have another look at it!!

good luck!!

Hmmm. so “properties of story i” does not contain any label or name or ID number?

Drag the InDesign app’s icon onto Script Editor’s icon to see its scripting dictionary. It will tell you (maybe) what code to use to select a story.

Hi,

I agree completely - it will be easier to pinpoint, select and target for editing the story with overflowing frame if there is some kind of unique story ID, much like the database ID of iTunes’ music tracks. I am not familiar either with InDesign so it’s hard to tell.

The suggestion of johnnylundy to drag the InDesign icon onto the Script Editor to see if there is any story identifier sounds like a good thing to do. If there is none, could you explore possibility of using the repeat loop index as your temporary identifier? (like the suggestion of Adam and johnnylundy earlier to select them out and create a new list of the “culprit” stories to be revisited later for editing). But it seems like you want to temporarily stop the loop at that point, pick out the “culprit” story and edit it while the repeat loop is still active.

I think that can be done by using an outside handler that can be called inside the repeat loop. In that handler, you open the story and do the editing (presumably within a “with timeout” block to allow enough time for editing or even using a delay). After editing is done, return the handler to the repeat loop to continue the scanning until the last story is examined.

I am not sure if this is what you want but FWIW, that’s my take on your problem.

archseed :slight_smile:

oops!

maybe i was to busy to actually read the intial post correctly!!
i see from what the posters above have replied i could have been a little bit off course for what you want.

apologies!!:confused:

I’m still not sure from how you worded your question what you are trying to select; the last (text) item is not valid because it’s overset and you wouldn’t be able to see it. If there is an extant overflow, you can select its parent or its contents with my code below. If you want to select the text frame that the story lives in, then no changes are necessary, but, if you want to select its text, then just delete the two dashes after the parenthesis on line 3.

try
tell document 1 of application "Indesign CS" to select ¬
(text frame -1 where its overflows = true)--'s text
end try

First of all, thank you all for feedback, appreciate it:) Basically I have no programming/scripting background, so large piece of what you guys write here sound like Chinese to me:)

My english still ain’t perfect even after couple of years of learning, so I’ll try to explain a bit more schematically. I want the script to perform action like this:
check if the textbox is overflowing:
→ if no, then go to next text frame and check again
→ if yes, then open dialog “This document contains…” and after clicking OK the text box containing overflowing will be selected.

Johnny & Archseed: sorry I didn’t specify my thoughts well. What I meant was, the list of generic numbers or labels like story1, story2, textbox18 etc. won’t be useful in a case of 40 textboxes and 10 different stories. Of course, every text box and every story have unique identifier, what I was also saying, they are not labelled manually (Indesign has a feature of “scripting label” to make the scripting easier by identyfying certain objects).

However the idea of array, or even setting an variable to label of last processed textbox is tempting, I have to try that out.

A quick update:
Marc: your 4 line solution does the job perfectly! Thanks a million!

Model: G5 1.8 dual
AppleScript: 1.10.7
Browser: Firefox 2.0.0.9
Operating System: Mac OS X (10.4)