0

Does Indesign trigger any events when a paragraph style object does change? Or is there any built in javascript functionality that can observe an object? Object.obserce and Proxy are not working in CS6.

2
  • Why the downvote?
    – mdomino
    May 31 '17 at 12:55
  • Possibly because the title of your question is not very descriptive. I was about to downvote it myself for that exact reason. Please try and accurately describe your question is its title. Thanks!
    – Vincent
    May 31 '17 at 13:21
1

The documentation states that you can attach event listeners to DOM objects such as myParaStyle.addEventListener but I could never got something to work with those.

But you can use an idleEvent listener and look around at possible styles edits:

#targetengine "onAfterSelectionChanged"
var main  = function() {

var currDocId, stylesDB = {};


var onAfterParagraphStyleEdit  = function ( evt ) {
    var doc = evt.parent, docId;
    if ( !app.documents.length ) return;
    doc = app.activeDocument;
    docId = doc.id;

    if  ( !currDocId 
    ||
    currDocId!=docId ) {
        currDocId = docId;
        stylesDB = getStylesDB(doc);
        return;
    }

try {
    compareStyles ( doc, stylesDB ) ;
}
catch(err)  {
alert ( err.line+"//"+err.message );
}
}

var it = app.idleTasks.itemByName ("onAfterParagraphStyleEdit" );

if  ( !it.isValid ) {
    it  =app.idleTasks.add({name:"onAfterParagraphStyleEdit", sleep:100});
    it.addEventListener(IdleEvent.ON_IDLE, onAfterParagraphStyleEdit, false);
}
}
main(); 
var compareStyles = function ( doc, db ) {
var pss = doc.allParagraphStyles, ps, psId, psProps,
 n = pss.length, diffs = [];

 while ( n-- ) {
     ps = pss[n];
     psId = ps.id;
    if (  !db[psId] )  {
        db[psId] = ps.properties.toSource();
    }
    else {
        psProps = ps.properties.toSource();
        if ( db[psId] !=  psProps) {
            diffs.push ( ps.name +"["+ps.id+"]" );
            db[psId] = psProps;
        }
    }
}

diffs.length && alert("Those styles were modified…\r"+diffs.join("\r"
) );
}
var getStylesDB = function ( doc ) {
var db = {};
var pss = doc.allParagraphStyles, ps,
 n = pss.length;

while ( n-- ) {
    ps = pss[n];
    db[pss[n].id] = ps.properties.toSource();
}

return db;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.