I just want a function to run whenever a new page is created in inDesign. Adobe's documentation appears to let you attach event handlers to nearly all objects, but they don't give any examples of how to do this past the document level.
var myEventListener = app.eventListeners.add("afterNew", myAfterNewHandler);
How do I get this to trigger on creation of a new page. I've already tried replacing app
with app.document.pages
and it did not work.
I couldn't find any smart way.
following snippet works only with adding new page icon in page panel or it's shortcut,
setting page length in document setting dialog cause modal dialog error.
var doc = app.activeDocument;
var p = doc.pages.length;
var listener = doc.addEventListener(
MutationEvent.AFTER_ATTRIBUTE_CHANGED,
create_dummy
);
listener.name = 'ooo';
function create_dummy(e) {
if (e.attributeValue.constructor.name === 'Page') {
if (p < e.currentTarget.pages.length) {
var tf = e.attributeValue.textFrames.add();
tf.geometricBounds = [1,1,72,144];
tf.parentStory.contents = e.timeStamp.toString();
}
p = e.currentTarget.pages.length;
}
}
thank you
mg