7 Replies Latest reply on Oct 21, 2013 4:10 AM by bwaldie

    [AS] [CS5.5] Weird InDesign save event listener behavior

    bwaldie

      I've written an AppleScript for a client, and I've enabled it, via an event listener, to run when any of the following events occur: beforeSave, beforeSaveAs, beforeSaveACopy, afterRefert, beforePrint, beforeExport.  When these events occur, an update is made to the document.  Specifically, content is added to a text frame, and some styling may occur.  This works great for all of the events above.  There's just one strange thing that's occurring...

       

      When the beforeSave event occurs, the script runs, the document is updated, the save completes, and then the document immediately enters an unsaved state again.  This issue only occurs with certain documents for certain users.  Dozens of people are using the script, and only a handful are encountering this issue.

       

      Software environment is: Adobe InDesign CS 5.5 and OS X 10.5.8 through 10.7.3.

       

      Has anyone else has encountered something like this?  Why would a document appear unsaved when a script is executed by a beforeSave event?  Should the save occur after the script has finished?  And, why would it occur in some situations, and not others?

       

      I've tried isolating the code that's causing the problem, and while I found the exact line (setting content in a text frame), I was unable to identify why it's occurring, or a suitable workaround.

       

      I apologize, but due to a confidentiality agreement, I'm unable to share the source code of the script in question.  I tried writing a brand new event listener script that simply creates a text frame on the document.  This new script, however, does not seem to reproduce the problem.  So, it's not much use for diagnostics.  If anyone wants to try it, however, here's the code...

       

      1. Save the following as "Test.scpt" to the Desktop...

       

      try

        main(evt)

      on error

        updateDoc()

      end try

       

      on main(myEvent)

                tell application "Adobe InDesign CS5.5"

                          set theEventType to ((event type of myEvent) as string)

        updateDoc()

                end tell

      end main

       

      on updateDoc()

                tell application "Adobe InDesign CS5.5"

                          tell active document

                                    tell active page of front layout window

                                              make new text frame with properties {geometric bounds:{"10pt", "-110pt", "110pt", "-10pt"}, stroke color:"Black"}

                                    end tell

                          end tell

                end tell

      end updateDoc

       

      2. Run the following to enable the event listeners:

       

      set theScript to (path to desktop folder as string) & "Test.scpt"

      tell application "Adobe InDesign CS5.5"

        delete every event listener

        make new event listener with properties {event type:"beforeSave", handler:theScript, cancelable:true}

        make new event listener with properties {event type:"beforeSaveAs", handler:theScript, cancelable:true}

        make new event listener with properties {event type:"beforeSaveACopy", handler:theScript, cancelable:true}

        make new event listener with properties {event type:"afterRevert", handler:theScript, cancelable:true}

        make new event listener with properties {event type:"beforePrint", handler:theScript, cancelable:true}

        make new event listener with properties {event type:"beforeExport", handler:theScript, cancelable:true}

      end tell

       

      I appreciate any input or suggestions.

       

      -Ben

        • 1. Re: [AS] [CS5.5] Weird InDesign save event listener behavior
          mrslother

          Did you ever come to a conclusion on this? I am facing a very similar problem: during beforeSave I mod the file then afterSave I undo the changes (all to change the file's preview image thumbnail) but that leaves the file "dirty" and wanting to be saved. I would like to forcibly change the document.modified property but it is read only.

          • 2. Re: [AS] [CS5.5] Weird InDesign save event listener behavior
            bwaldie Level 1

            Unfortunately, I never did identify a solution. To recap, my script ran on the beforeSave event. After the script finished and the document was saved, the document immediately appeared unsaved, even though the script did not perform additional modifications.  The problem occurred very randomly, and was not possible to consistently reproduce.  I encountered the problem with CS5.5. I have not seen it yet with CS6 or CC.

             

            -Ben

            • 3. Re: [AS] [CS5.5] Weird InDesign save event listener behavior
              mrslother Level 1

              My scenario is slightly different as I make mods during beforeSave then undo them afterSave. So I expect to have a modified/dirty doc after the save.

               

              My scenario is here:

              http://forums.adobe.com/message/5760168#5760168

               

              I am disappointed that there seems to be so little Adobe help on these forums. That compounded with the lack of reasonable documentation on their event model makes me wonder if there are better alternatives.

              • 4. Re: [AS] [CS5.5] Weird InDesign save event listener behavior
                mrslother Level 1

                Oh, one last Hail Mary...

                 

                While messing with beforeSave, it seems that at least some parts of the file are already commited for the save when this event is fired. For example in my beforeSave I modify layer properties (the printable property) so that the preview thumbnail image shows non-printing layers. This strategy fails. It is as if the preview image has already been calculated and committed before the beforeSave event occurs.

                 

                Something that may work for you is to capture the beforeInvoke event on the "Save" MenuAction. This way you can affect your changes before any of the Save work is invoked. It will also work with CTRL+S (since that simply invokes the MenuAction). When I do this it works fine for my preview image however the side effect is that the beforeInvoke event is not fired when you save the doc while closing it. For me that renders this method moot.

                • 5. Re: [AS] [CS5.5] Weird InDesign save event listener behavior
                  bwaldie Level 1

                  Thanks for the ideas regarding beforeInvoke, Ben.  I will try to check that out.  In my situation, here's essentially how my script is working...

                   

                  BeforeSave is invoked.

                      

                  Script makes a change to the document, which should be captured in the saved file.

                   

                  Document saves.

                   

                  Document appears saved for a moment, and then appears unsaved (asterisk in the document title).

                   

                  My biggest problem is that this behavior isn't consistent.  I have dozens of users, all running the same script, and the problem only occurs with certain users and at random times. I can move a problematic document from a user's machine to a different machine, and the problem doesn't occur there.  It's very difficult to troubleshoot because I can't reproduce it consistently.

                  • 6. Re: [AS] [CS5.5] Weird InDesign save event listener behavior
                    Laubender Adobe Community Professional & MVP

                    @Ben – are all installed InDesign versions patched to the same point product?
                    Say InDesign 7.5.3 for InDesign CS5.5 ?

                     

                    Or are some users on InDesign 7.5.2, 7.5.1 or even 7.5.0 ?

                     

                    Uwe

                    • 7. Re: [AS] [CS5.5] Weird InDesign save event listener behavior
                      bwaldie Level 1

                      @Uwe - Yes, all users are running the same version of InDesign - 7.5.3.

                       

                      Regards,

                       

                      -Ben