2 Replies Latest reply on Jul 27, 2017 4:02 AM by Loic.Aigon

    Checking if a document is already open

    Lucas02 Level 1

      Our Design department is having a permissions problem with InDesign not creating Lock files on our AFP Server.

      I am looking to use an InDesign script that checks if the current file is already in use.

      Any help would be appreciated.

        • 1. Re: Checking if a document is already open
          tpk1982 Level 4

          Is this help?

           

          var doc1=File.openDialog ("Choose your file",true)
          try{
          app.open(doc1);
          }
          catch(e){alert("File already opened")}
          
          • 2. Re: Checking if a document is already open
            Loic.Aigon Adobe Community Professional

            I think you don't need to provoke an error to achieve that.

             

            function checkIfSomeFileIsOpened ( someUrl ) {
            
            var docs = app.documents.everyItem().getElements(),
            n = docs.length, docUrl, doc, checkFileUrl = File (someUrl).absoluteURI ;
            
            if ( !n) return false;
            
            while ( n--  ) {
            doc = docs[n];
            url = doc.properties.fullName;
            if ( File ( url ).absoluteURI == checkFileUrl ) {
            return true;
            }
            }
            
            
            return false;
            }
            
            
            var url = "/Users/ozalto/Desktop/test1.indd";
            checkIfSomeFileIsOpened ( url );