Skip to main content
Inspiring
February 18, 2015
Question

Way to detect if an Indesign Document has unsaved changes

  • February 18, 2015
  • 3 replies
  • 1553 views

I have an InDesign document that I have saved. After saving the document, I make some changes to it. Now I want to detect if there are any unsaved changes in the document through JSX. I have tried to use the property document.saved, but this method only tells me if the document was saved for the first time.

If have some unsaved changes in a document that has been previously saved, document.saved still returns true.

Is there any other way to detect unsaved changes for a document?

This topic has been closed for replies.

3 replies

Peter Kahrel
Community Expert
Community Expert
February 18, 2015

Or you can check if there's anything in the undo stack:

if (app.documents[0].undoHistory.length > 0) { // Changes were made

Peter

Inspiring
February 19, 2015

yes that can be done, but again it comes down to polling.

I don't want to poll to check if the document state has become dirty.

There should be some event(by attaching some event listener) which can notify that document has becomes dirty.

vinothr
Inspiring
May 20, 2016

Try to add an event listener to document layout window for LayoutWindow.AFTER_ATTRIBUTE_CHANGED.

This should notify you when any attribute of layoutwindow changes (e.g., layoutwindow name changes when doc is modified).

If this not works, try LayoutWindow.AFTER_SELECTION_ATTRIBUTE_CHANGED. When selection events on document layout would notify you. This is a tweak, may not be efficient. But may work for you. Note that with AFTER_SELECTION_ATTRIBUTE_CHANGED you may not get notified if you try to add a para/char style (where doc may get dirty).

Chinnadk
Legend
February 18, 2015

Or you can try this.

alert(app.menuActions.itemByName("$ID/Revert").enabled)

if it returns true then the document has the unsaved changes.

Regards,

Chinna

Community Expert
February 18, 2015

Thank you Chinna for reminding me :-)

Uwe

Community Expert
February 18, 2015

@Kapoor – you could tell by the layoutWindow name. If a * is in front of the name, the document is not fully saved.

if(app.documents[0].layoutWindows[0].name.match(/^\*/)){$.writeln("doc not saved!")};

At least this is true for layout windows on Mac OSX.

In Windows the little * could be at the end of the name.
Can't remember. Currently I'm on OSX 10.7.5.

If it is indeed on the left right side of the name, you have to check on what OS the script is running and do the match accordingly.

Uwe

//EDIT

Community Expert
February 18, 2015

Or expand the match that both sides are checked.

Uwe

Community Expert
February 18, 2015

Of course you have always to compare with the name of the document, in case somone named the document with a * at the beginning.
It's unlikely, that will happen on the end of the name ;-)

Uwe