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

Selecting the first file from a group of opened files in Photoshop

New Here ,
Oct 10, 2013 Oct 10, 2013

Hi, I've been digitizing microfiche with 200 or so pages photographed onto one image file, laid out in a grid pattern. I've been using actions in Photoshop to cut out one page, create a new file in Photoshop from that page, then return to the first, master file and do it again with the next page in the series. So when it is complete I have each individual page as an individual image file which I then save with a batch process. I've been doing this for a while and have managed to make it work but I always run into the problem, when creating this action again, of getting Photoshop to select that first master file each time instead of selecting just the previous file. I know I can get it to select the previous file, or the previous file -1, -2, -3, etc. I've somehow been able to get this to work in the past by creating an action that selects a large enough group back, like previous file -19 or something, and through some bug or sheer luck it has worked and will always select that first file. But it doesn't always work and it always takes some frustration to luck into it when it does. Now I can't seem to get it to work at all. Is there a straightforward way I can simply tell it to select the first file everytime? If not, does anyone know how or why the method I used previously sometimes works and sometimes doesn't, and how I can make it work again? I'm using PS CS5 in Windows 7. Thanks!

TOPICS
Actions and scripting
1.8K
Translate
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
Enthusiast ,
Oct 10, 2013 Oct 10, 2013

Just put this code on a file and put that 'namedfile.jsx' inside the scripts folder on photoshop.

Open or re-open photoshop to load the script and create an action linked to a shortcut selected by you and save this script going to File>Scripts>namedfile.jsx

It is just to press the shortcut key and the active image go back to the image opened before.

When it is the first one it runs the script the same but it remains there.

Here is the script:

//////////////////////////////////////////////////////////

// Go back to the previous opened image

//////////////////////////////////////////////////////////

#target photoshop

// Go back to the previous opened image (not the previous viewed) . If it is the first, it remain there.

if(documents.length>0) {

    var thisIndexImage = getActiveDocumentIndex();

    var theDocs = app.documents;

    if ( thisIndexImage != 0 ) {

        var flatAnterior = theDocs[thisIndexImage - 1];

        } else {

        var flatAnterior = theDocs[0];

        }

    app.activeDocument = flatAnterior;

} else {

    alert ("You must have opened images to run this script.")

}

////////////////////////////////////////////////////////////////////////////////////////////////////////

// Get the active document number - the number of opening order

function getActiveDocumentIndex(){

     var ref = new ActionReference();

     ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

     return desc = executeActionGet(ref).getInteger(stringIDToTypeID('itemIndex'))-1;

}

_______________________

If you want to go directly to the first of all the images (in opening order) it is simpler:

Just create this script:

var first = app.documents[0];

app.activeDocument = flatAnterior;

Translate
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
Guru ,
Oct 10, 2013 Oct 10, 2013
LATEST

var first = app.documents[0];

app.activeDocument = flatAnterior;

That should be:

var first = app.documents[0];

app.activeDocument = first;// the reference to documents[0]

Or skip the variable as it will not be used.

app.activeDocument = app.documents[0];

As to how you selected the first document in an action. As far as I know you can only select  by offset. And if you use the keyboard shortcuts to cycle through the documents it doesn't stop but wraps around i.e. if you are on the last doc selecting next selects the first. So I don't know how you recorded your first action.

Translate
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