Skip to content

Instantly share code, notes, and snippets.

@milligramme
Last active November 18, 2015 10:25
Show Gist options
  • Select an option

  • Save milligramme/f9a70e952903db8b0ad3 to your computer and use it in GitHub Desktop.

Select an option

Save milligramme/f9a70e952903db8b0ad3 to your computer and use it in GitHub Desktop.
update toc in indesign document
#target "InDesign"
var update_toc = function (doc, opt) {
var story_len = doc.stories.length;
var _story, _toc_tfs;
var toc_styles = doc.tocStyles;
for (var i=0, len=toc_styles.length; i < len ; i++) {
_story = doc.createTOC(toc_styles[i], true);
if (opt.only_used && doc.stories.length > story_len ) {
_toc_tfs = _story[0].textContainers;
for (var j = _toc_tfs.length - 1; j >= 0; j--) {
// remove textfreame created by unused toc-style
_toc_tfs[j].remove();
}
}
};
};
var doc = app.documents[0];
update_toc(doc, {only_used: true});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment