4 Replies Latest reply on Jul 20, 2012 9:06 AM by Pedro Cortez Marques

    How to Select the Document just back of the Active Document

    krishna chip Level 1

      If there are 5 documents open in photoshop I want to select the document just behind or back of the Active Document , using script.

       

      One of my friend suggested me the bleow script, but it is selecting the previous document, not exactly the document back of the active document.

      please help me.

       

      var id85 = charIDToTypeID( "slct" );
          var desc21 = new ActionDescriptor();
          var id86 = charIDToTypeID( "null" );
              var ref11 = new ActionReference();
              var id87 = charIDToTypeID( "Dcmn" );
              ref11.putOffset( id87, -1 );
          desc21.putReference( id86, ref11 );
      
       executeAction( id85, desc21, DialogModes.NO )
      
        • 1. Re: How to Select the Document just back of the Active Document
          c.pfaffenbichler Level 9

          I may be wrong but I don’t think what you want is possible in DOM or with ActionDescriptors reliably when more than two documents are open as the order in which open images are stacked is not reflected in their indices.

           

          Possible workarounds might be:

          • Close the active Document, do whatever with the now active one, then re-open the originally active one.

          • Use platform dependent code that utilizes OS behaviour. Of this I am not at all sure and could probably not help even if it was possible, but on Mac OS at least one can switch between document windows in an application with an OS command, so I assume one might be able to use that.

           

          I’m curious if I have overlooked something obvious and if so hope on of the regulars can set me straight.

          • 2. Re: How to Select the Document just back of the Active Document
            mangalarajiv Level 1

            var id85 = charIDToTypeID( "slct" );
                var desc21 = new ActionDescriptor();
                var id86 = charIDToTypeID( "null" );
                    var ref11 = new ActionReference();
                    var id87 = charIDToTypeID( "Dcmn" );
                    ref11.putOffset( id87, +1 );
                desc21.putReference( id86, ref11 );
              executeAction( id85, desc21, DialogModes.NO )

             

             

            The above mentioned script would active the next document from the active document.

            Please let us know your feedback.

            • 3. Re: How to Select the Document just back of the Active Document
              c.pfaffenbichler Level 9

              It does not work for me in the way I think the OP intended.

               

              I created 5 new documents, selected the third and on running the Script the 4th became active although the 5th would have been the one behind the 3rd.

               

              The index does not represent the order in which the images are stacked.

              • 4. Re: How to Select the Document just back of the Active Document
                Pedro Cortez Marques Level 3

                I had the same problem. I did not want to go back to the "last viewed" doc but to the doc opened before the active one.

                I use this on F1 key to go back to the previous opened document (index order -1).

                It works great.

                 

                 

                //////////////////////////////////////////////////////////////////////////////////////////////////////////
                #target photoshop
                // Go back to the last opened doc. If it is the oldest opened one it does not give error window and stays on it.
                if(documents.length>0) {
                    var thisIndexImage = getActiveDocumentIndex();
                    var theDocs = app.documents; 
                    if ( thisIndexImage != 0 ) {
                        var openedBefore = theDocs[thisIndexImage - 1];
                        } else {
                        var openedBefore = theDocs[0];
                        }
                    app.activeDocument = openedBefore;
                } else {
                    alert ("You need to have any opened documents to apply this script.")
                }
                
                // Functions
                function getActiveDocumentIndex(){
                     var ref = new ActionReference();
                     ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
                     return desc = executeActionGet(ref).getInteger(stringIDToTypeID('itemIndex'))-1;
                }