Skip navigation
krishna chip
Currently Being Moderated

How to Select the Document just back of the Active Document

Apr 15, 2012 6:17 AM

Tags: #photoshop #adobe #script #javascript #action_script_3 #scripting #photoshop_cs5 #selection_issues

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 )
 
Replies
  • Currently Being Moderated
    Apr 15, 2012 7:49 AM   in reply to krishna chip

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 16, 2012 10:57 PM   in reply to c.pfaffenbichler

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 16, 2012 11:34 PM   in reply to mangalarajiv

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 20, 2012 9:06 AM   in reply to krishna chip

    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;
    }
    
     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points