I got an requirement to find out if content in text frame got changed or not through action script. Till now i am comparing with my server side data to check content from indesign document text frame, but now i would like to check if any default flag there to avoid server side call.
Track changes seems the way to go indeed. An alternative might be to use idle events to monitor stories changes. Basically what Josh just suggested.
#targetengine "storiesChanges"
main();
function main()
{
var db = {};
var myIdleTask = app.idleTasks.item("checkStories");
if ( !myIdleTask.isValid ) {
myIdleTask = app.idleTasks.add({name:"checkStories", sleep:100});
myIdleTask.addEventListener(IdleEvent.ON_IDLE,onIdleEventHandler, false);
}
function onIdleEventHandler(myIdleEvent)
{
var doc = app.properties.activeDocument;
if ( !doc ) {
db = {}
return;
}
var sts = doc.stories, st, id;
var n = sts.length;
while ( n-- ) {
st = sts[n];
id = st.id;
if ( !db[id] ) {
$.writeln ("Storing "+id );
db[id] = st.contents;
}
else if ( db[id]!=st.contents ) {
$.writeln ( "Some changes were made on story "+id+" at "+(new Date()) );
db[id] = st.contents;
}
else {
$.writeln ( "No changes were made for story "+id );
}
}
}
}