• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to Select the Document just back of the Active Document

New Here ,
Apr 15, 2012 Apr 15, 2012

Copy link to clipboard

Copied

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 )

TOPICS
Actions and scripting

Views

2.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Apr 15, 2012 Apr 15, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 16, 2012 Jul 16, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 16, 2012 Jul 16, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 20, 2012 Jul 20, 2012

Copy link to clipboard

Copied

LATEST

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;

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines