Learning in public — this reference is being written in the open. Unfinished pages are excluded from search engines.
paged.IDML Reference
Scripting (paged.*)

Your first script

A hands-on, five-step introduction to the paged.* scripting API — read the document, address an element, write a property, author from scratch, and undo — each step runnable in a live editor.

Tier: BeginnerBeginnerItutorial

In short in five short steps you'll read a document, change a frame, build one from scratch, and undo it — every step running in a real editor you can edit. By the end you'll know the three moves every script is made of: read, address, write.

1. Read the document

Everything starts with a read. paged.tree() returns the document hierarchy — as a JSON string, so parse it first. Press Run:

Open ↗paged.* · seed: one-text-frame-selected
Loading editor…
Look for: The console prints one spread → one page → one text frame.
Console
Run a script to see console output here.

Every read (tree, selection, stories, pages, …) returns a JSON string. Forgetting JSON.parse is the single most common scripting mistake — "[]".length is 2, not 0.

2. Address an element

To change something you need its id. The frame in this document is already selected, so read the selection and turn it into an address — kind:id:

Open ↗paged.* · seed: one-text-frame-selected
Loading editor…
Look for: The console prints the selected frame's address, e.g. textFrame:u3.
Console
Run a script to see console output here.

3. Write a property

Now address it and write. paged.set(id, path, value) takes a settable path and re-renders immediately:

Open ↗paged.* · seed: one-text-frame-selected
Loading editor…
Look for: The frame fills red, gains a thick border, and rotates 12°.
Console
Run a script to see console output here.

4. Author from scratch

Reads and writes work on what's there — but you can also create. Get a page id from paged.pages(), make a frame (it returns its new id), and pour text in:

Open ↗paged.* · seed: blank
Loading editor…
Look for: A new text frame appears on the blank page with a sentence in it.
Console
Run a script to see console output here.

5. Undo

Every write goes through the editor's Operation channel, so paged.undo() reverts it exactly as ⌘Z would:

Open ↗paged.* · seed: one-text-frame-selected
Loading editor…
Look for: The frame fills red, then undo reverts it, then redo re-applies it.
Console
Run a script to see console output here.

Where to go next

On this page