3 Replies Latest reply on May 5, 2015 3:32 PM by Daniel Sterchi

    Rename the opening file & then open it

    Arihant Jain Mg

      Hi,

       

      I am looking for a script which can -

      1. On opening a file rename it. For e.g. Rename "FileName1.indd" to "FileName1-in-use.indd"

      2. Then open the file "FileName1-in-use.indd"

      3. Then on closing rename it back to "Filename1.indd"

       

      Is it possible?

       

       

      Regards

        • 1. Re: Rename the opening file & then open it
          Vamitul Level 4

          While not difficult, it is kind of useless, as Indesign will automatically "lock" a file that is in use, so other people won't be able to open it until you finish with it.

          • 2. Re: Rename the opening file & then open it
            Arihant Jain Mg Level 1

            We are using a sync software & that software is not syncing the lock file & other users are able to make changes.

            • 3. Re: Rename the opening file & then open it
              Daniel Sterchi Adobe Community Professional

              Hi there

               

              I am not sure if this meets your needs. What about «race conditions»?

               

              Give this a try.

               

              Kind regards

               

              Daniel (from Switzerland)

               

              main();
              exit();
              
              function main() {
              
                  var myDoc = File.openDialog ("InDesign-File", fileMaskINDD);
                 
                  if (myDoc != null) {
                      // get the actual filename
                      myFileName = myDoc.name.substr(0, myDoc.name.indexOf("."));
                      myNewFileName= myFileName.replace(myFileName, myFileName+"-in-use.indd");
                     
                      // rename the actual doc
                      myDoc.rename(myNewFileName);
                     
                      // open the InDesign document
                      tempDoc = app.open(myDoc);
                     
                      // do your stuff here
                      do_your_stuff_here(tempDoc);
                     
                      // save and close
                      tempDoc.save();
                      tempDoc.close();
              
                      // rename the document again
                      myDoc.rename(myFileName+ ".indd");
                             
                      alert("I did my job, what about yours?");
                  }
              }
              
              function do_your_stuff_here(myDoc) {
                 
                  alert("Do your stuff here");
              }
              
              /*
                  To filter the files and only show InDesign files or directories
              */
              function fileMaskINDD(myFile) {
              
                if (myFile.constructor.name == "Folder") { return true }
                if (myFile.name.slice(-5) == ".indd") { return true }
                return false;
              }