the first dozen lessons dealt with scripts that address InDesign documents or the application itself. the next few will focus on addressing the contents of files — the pages and the stuff on them. if you’re unconvinced that scripting the contents of files is useful to you — check out the short videos on youtube — one of those may change your mind.
the things on a page are collectively called page items — these include rectangles, text frames, ovals, polygons, graphic lines and, the frequently problematic, groups. fill a single-page file with different types of page items and then run this from script editor (found in applications > applescript) — as always, update the script to your version of Indesign :
tell application "Adobe InDesign CS4" activate tell active document select every page item end tell end tell
then change “page item” to “rectangle” and run it again. cool eh? you can use “rectangles” instead of “every rectangle” if it makes more sense to you.
if you wanted to select the rectangles and text frames but not the other page items, you could do it like this (notice that you can’t use “select every rectangle and every text frame”) :
tell application "Adobe InDesign CS4" activate tell active document select every rectangle select every text frame existing selection add to end tell end tell
well, that all works fine if you’ve only got stuff on one page. but it will fail with most documents because you cannot simultaneously select items on multiple pages — and “every rectangle” means every rectangle in the entire document. most of the time you need to specify a page or spread :
select every page item of page 3
you could also use “…in page 3″ — whatever takes your fancy.
previous lessons have mentioned how torturous applescript syntax can be. well, check this out — the way to select items of a particular layer of a particular page :
tell application "Adobe InDesign CS4" activate tell active document select (page items of page 3 whose (name of item layer is "Layer 2")) end tell end tell
all these examples have used the command “select”. no doubt you can work out what would happen if you substituted another command — such as “delete”, “duplicate” or “bring to front”.