Site logo

Table of contents

How to update TOC

You can update TOC using the 2-nd parameter of the createTOC() which replaces the existing TOC.


function main() {
	var doc = app.activeDocument;
	var tocStyle = doc.tocStyles[0];
	doc.createTOC(tocStyle, true);

Alternatively, you can select the text frame containing the TOC and invoke the menu item, like so:

var contentsTextFrame = getItemFromCollection("contents", g.doc.textFrames);
if (contentsTextFrame != null) {;

How to find TOC

What you can find is if a given story's storyType is of the kind StoryTypes.TOC_STORY. And you could address the first frame of a given story with textContainers[0] from its textContainers array.