7 Replies Latest reply on Dec 18, 2013 9:43 AM by Mi_D

    Auto save

    mlonthebeach Level 1

      Is it possible to set up a script that would run automatically on file open and save a copy periodically, or perhaps better, one that would run on file close

        • 1. Re: Auto save
          Mi_D Level 3

          copy the script in "startup scripts" folder and restart the indesign application

           

          #targetengine "MySnazzyEngine";

          var eventListener;

          main();

          function main()

          {

                  eventListener = app.addEventListener("afterOpen", openEvent, false);

          }

           

          function openEvent(eventInfo)

          {

              //Here You  call your script

                  alert('open');

          }

           

          Mi_D

          • 2. Re: Auto save
            Laubender Adobe Community Professional & MVP

            @Mi_D – that is all good and well, but the event will even fire, if you open another LayoutWindow of the same file. Or if you open the StoryWindow of the story editor.

             

            In the context of the original question, this event fires way too much…

             

            Worse, if you open a file:


            The event will fire one time even before the to be opened document can be shown in a window. And another time after the document is shown in a window.*

             

            If a new document is created, the event will fire only one time after the new document is shown in a window.*

             

            If you open the Story Editor window, the event fires again one time.
            If you open another layout window of a opened document the evnet will fire one time

             

            *these are the only occasions where you possibly want to save the document to a copy in a special folder.

             

            The big question is: how to determine what window belongs to what file, if several files are opened or if new windows of already open files are created.

             

            Code tested on Mac OSX 10.6.8 with InDesign CS5.5, run from ESTK, not running in main().

             

            #target InDesign;
            #targetengine "AlertAfterOpenWindow";
            
            var counter = 0;
            
            app.addEventListener("afterOpen", openEvent, false);
            
            function openEvent(){
            
                ++counter;
                alert("afterOpen-event fired: "+counter);
            
                };
            

             

            To the OP: if you want to test this with the ESTK (ExtendScript Toolkit) and want to get rid of the alert message in InDesign, simply restart InDesign.

             

            Uwe

            • 3. Re: Auto save
              mlonthebeach Level 1

              Since I'm not familiar with scripting, not sure if this is what we need. We need a script that will auto save an active document every 15 minutes while it's being worked on.  Is that what the script above will do?

              • 4. Re: Auto save
                Mi_D Level 3

                thanks launbender for your feedback regaiding code

                it's help me lot of for me at time write code.. In future also i hope i get  feedback that help me

                 

                Mi_D

                • 5. Re: Auto save
                  Laubender Adobe Community Professional & MVP

                  @mionthebeach – no. This code snippet will not save your open documents every 15 minutes.

                  It's just an reaction to Mi_D's script snippet. My code is showing an alert every time the "afterOpen" event will fire.

                   

                  That means basically every time you open a document (then it fires two times), every time you create a new document, every time you open a new layout window or a new story window…
                  It's just a showcase to test, if the event "afterOpen" could be used reliably for saving a document.

                   

                  Uwe

                  • 6. Re: Auto save
                    Laubender Adobe Community Professional & MVP

                    @mionthebeach – you can regard both of the code snippets as trial balloons to find out if your idea can be implemented into a larger script at all.

                     

                    Something like a corner stone of a larger building. Or, if we are unlucky, just a brick laying around in the jungle…

                     

                    Uwe

                    • 7. Re: Auto save
                      Mi_D Level 3

                      @mionthebeach

                      As per ur thread how to run script when open document

                       

                       

                      @ .Laubender  code

                       

                      function openEvent(){    

                        ++counter;

                       


                      //YOUR FUNCTION....

                       

                       


                        alert("afterOpen-event fired: "+counter); 

                           };

                      Mi_D