how to skip layer if not found? (Indesign CS2)

Hi there,
In Indesign I need to place a small box of text just outside the document, containing a code that referrs to a language on a layer.
E.g. the document contains Dutch (NLNL) and Danish (DKDK). I’ve been able to create a box with the code to be placed in the correct layer, just outside my A4 page, matching the specific layer (with the same code name).
Now, what I would like is to add all the languages that are common but which will not always be necessary - there can be up to 15 different languages, one per layer, but also sometimes only 3, 4 or 8. One script to rule them all, as it were :wink: In the script below that would be the French layer. If I run the script without a layer called FRFR of course I get an error. Can anyone help me? The script should ignore the layers not present.
Another question: how can I add this to every page? I’ve only got it running for page 1.
I’m quite ignorant here, but I’m proud I’ve got it figured out as far as I got, so help is much appreciated!
Elsa

tell app "Adobe InDesign CS2"
	activate
	set myDoc to active document
	tell myDoc
		--SET THE UNIT OF MEASURE
		set the properties of view preferences to {horizontal measurement units:millimeters, vertical measurement units:millimeters, ruler origin:page origin}
		

		--CREATE A TEXT FRAME ON the page and the layer NLNL
                set active layer of layout window 1 to first layer whose name contains "NLNL"
		set myTargetFrame to make new text frame with properties {geometric bounds:{302, 30, 307, 80}, contents:"NLNL"}
		
		--CREATE A TEXT FRAME ON the page and the layer DKDK
		set active layer of layout window 1 to first layer whose name contains "DKDK"
		set myTargetFrame to make new text frame with properties {geometric bounds:{302, 30, 307, 80}, contents:"DKDK"}
		
		
		--CREATE A TEXT FRAME ON the page and the layer FRFR
		set active layer of layout window 1 to first layer whose name contains "FRFR"
		set myTargetFrame to make new text frame with properties {geometric bounds:{302, 30, 307, 80}, contents:"FRFR"}
		
	end tell
end tell



Elsa:

Script the Layers of the Master Page, NOT the individual pages. If you need local changes (individual pages) then you can override the Master and adjust from there.

Have Fun :smiley:
Jim Neumann
BLUEFROG