Skip to main content
joshakatz
Known Participant
May 4, 2023
Answered

help loading images into layers by filename

  • May 4, 2023
  • 2 replies
  • 4963 views

Hello, I'm having an issue that I'm unable to find help with in the forum, if the answer already esists I apologize.

 

I have a series of photograohs that were worked on by a professional retoucher and the original images in lightroom. To keep my lightroom catalog clean I am now chosing Edit in Photoshop in lightroom to open each image as a psd and then dragging the cooresponding jpeg to the top as a new layer and resaving to reflect changes in lightroom.  While this does work, I have dozens of images and it's taking forever. 

 

is there a script to automatically align an external file with a currently open file in photoshop that could save me some time?

 

 

thank you in advance

-Josh

This topic has been closed for replies.
Correct answer Stephen Marsh

Don't have any unsaved files open when running this script.

 

If you are using PSD, I have simplified the code to save in the current file format, by simply closing/saving the edited file. As the PSD options are no longer set, you might have to set maximise compatibility depending on your preferences. If TIFF you may or may not need to select save options.

 

Does this 1.1 version work without locking up? It obviously doesn't lock up for me, but I don't use Lr and I'm not sure of the issue with resaving back to a file that is in your Lr library/catalogue.

 

/*
Layer & Save Matching Retouched JPEG over All Open PSD Files.jsx
v1.1 - 7th May 2023, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/help-loading-images-into-layers-by-filename/td-p/13769691
Notes:
All open files should have been previously saved, unsaved files may interrupt the batch processing
JPEG file names must match the open PSD name, with the addition of "_retouched.jpg" at the end of the doc name
*/

#target photoshop

if (app.documents.length > 0) {
    (function () {
        var jpgFolder = Folder.selectDialog('Please select the retouched JPEG folder:');
        if (jpgFolder === null) return;
        var savedDisplayDialogs = app.displayDialogs;
        app.displayDialogs = DialogModes.NO;
        while (app.documents.length > 0) {
                var psdName = activeDocument.name.replace(/\.[^\.]+$/, '');
                var jpgName = psdName + "_retouched.jpg";
                var jpgFile = jpgFolder + '/' + jpgName;
                placeFile(File(jpgFile), 100);
                activeDocument.activeLayer.rasterize(RasterizeType.ENTIRELAYER);
                activeDocument.close(SaveOptions.SAVECHANGES);
        }
        app.displayDialogs = savedDisplayDialogs;
        app.beep();
    })();
}
else {
    alert('One or more previously saved docs must be open to use this script!');
}

function placeFile(file, scale) {
    try {
        var idPlc = charIDToTypeID("Plc ");
        var desc2 = new ActionDescriptor();
        var idnull = charIDToTypeID("null");
        desc2.putPath(idnull, new File(file));
        var idFTcs = charIDToTypeID("FTcs");
        var idQCSt = charIDToTypeID("QCSt");
        var idQcsa = charIDToTypeID("Qcsa");
        desc2.putEnumerated(idFTcs, idQCSt, idQcsa);
        var idOfst = charIDToTypeID("Ofst");
        var desc3 = new ActionDescriptor();
        var idHrzn = charIDToTypeID("Hrzn");
        var idPxl = charIDToTypeID("#Pxl");
        desc3.putUnitDouble(idHrzn, idPxl, 0.000000);
        var idVrtc = charIDToTypeID("Vrtc");
        var idPxl = charIDToTypeID("#Pxl");
        desc3.putUnitDouble(idVrtc, idPxl, 0.000000);
        var idOfst = charIDToTypeID("Ofst");
        desc2.putObject(idOfst, idOfst, desc3);
        var idWdth = charIDToTypeID("Wdth");
        var idPrc = charIDToTypeID("#Prc");
        desc2.putUnitDouble(idWdth, idPrc, scale);
        var idHght = charIDToTypeID("Hght");
        var idPrc = charIDToTypeID("#Prc");
        desc2.putUnitDouble(idHght, idPrc, scale);
        var idAntA = charIDToTypeID("AntA");
        desc2.putBoolean(idAntA, true);
        executeAction(idPlc, desc2, DialogModes.NO);
    } catch (e) { }
}

 

 

2 replies

Stephen Marsh
Community Expert
May 7, 2023

@joshakatz 

 

Try the following script, it is designed to work with open PSD files (you didn't answer my question if they were PSD).

 

It is presumed and required that all open PSD files have been previously saved (so that there is a backing path to the file on the drive), otherwise, the script may be interrupted. It is also presumed that the JPEG file name matches the PSD with the addition of "_retouched.jpg". If the path to the retouched JPEG folder is always the same, this could be coded into the script rather than being asked to select the folder.

 

/*
Layer & Save Matching Retouched JPEG over All Open PSD Files.jsx
v1.0 - 7th May 2023, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/help-loading-images-into-layers-by-filename/td-p/13769691
Notes:
All open files should have been previously saved, unsaved files may interrupt the batch processing
JPEG file names must match the open PSD name, with the addition of "_retouched.jpg" at the end of the doc name
*/

#target photoshop

if (app.documents.length > 0) {
    (function () {
        var jpgFolder = Folder.selectDialog('Please select the retouched JPEG folder:');
        if (jpgFolder === null) return;
        var psdOptions = new PhotoshopSaveOptions();
        psdOptions.embedColorProfile = true;
        psdOptions.alphaChannels = true;
        psdOptions.layers = true;
        psdOptions.spotColors = true;
        var savedDisplayDialogs = app.displayDialogs;
        app.displayDialogs = DialogModes.NO;
        while (app.documents.length > 0) {
            if (activeDocument.path) {
                var psdName = activeDocument.name.replace(/\.[^\.]+$/, '');
                var jpgName = psdName + "_retouched.jpg";
                var jpgFile = jpgFolder + '/' + jpgName;
                placeFile(File(jpgFile), 100);
                activeDocument.activeLayer.rasterize(RasterizeType.ENTIRELAYER);
                activeDocument.saveAs(new File(activeDocument.fullName), psdOptions);
                activeDocument.close(SaveOptions.DONOTSAVECHANGES);
            } else {
                alert("The file has never been saved!");
            }
        }
        app.displayDialogs = savedDisplayDialogs;
        app.beep();
    })();
}
else {
    alert('One or more previously saved docs must be open to use this script!');
}

function placeFile(file, scale) {
    try {
        var idPlc = charIDToTypeID("Plc ");
        var desc2 = new ActionDescriptor();
        var idnull = charIDToTypeID("null");
        desc2.putPath(idnull, new File(file));
        var idFTcs = charIDToTypeID("FTcs");
        var idQCSt = charIDToTypeID("QCSt");
        var idQcsa = charIDToTypeID("Qcsa");
        desc2.putEnumerated(idFTcs, idQCSt, idQcsa);
        var idOfst = charIDToTypeID("Ofst");
        var desc3 = new ActionDescriptor();
        var idHrzn = charIDToTypeID("Hrzn");
        var idPxl = charIDToTypeID("#Pxl");
        desc3.putUnitDouble(idHrzn, idPxl, 0.000000);
        var idVrtc = charIDToTypeID("Vrtc");
        var idPxl = charIDToTypeID("#Pxl");
        desc3.putUnitDouble(idVrtc, idPxl, 0.000000);
        var idOfst = charIDToTypeID("Ofst");
        desc2.putObject(idOfst, idOfst, desc3);
        var idWdth = charIDToTypeID("Wdth");
        var idPrc = charIDToTypeID("#Prc");
        desc2.putUnitDouble(idWdth, idPrc, scale);
        var idHght = charIDToTypeID("Hght");
        var idPrc = charIDToTypeID("#Prc");
        desc2.putUnitDouble(idHght, idPrc, scale);
        var idAntA = charIDToTypeID("AntA");
        desc2.putBoolean(idAntA, true);
        executeAction(idPlc, desc2, DialogModes.NO);
    } catch (e) { }
}

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

 

joshakatz
joshakatzAuthor
Known Participant
May 7, 2023

I just saved a group of images as psds as a test and the progress bar gets stuck again during "Writing Photoshop Format"

 

Stephen Marsh
Stephen MarshCorrect answer
Community Expert
May 7, 2023

Don't have any unsaved files open when running this script.

 

If you are using PSD, I have simplified the code to save in the current file format, by simply closing/saving the edited file. As the PSD options are no longer set, you might have to set maximise compatibility depending on your preferences. If TIFF you may or may not need to select save options.

 

Does this 1.1 version work without locking up? It obviously doesn't lock up for me, but I don't use Lr and I'm not sure of the issue with resaving back to a file that is in your Lr library/catalogue.

 

/*
Layer & Save Matching Retouched JPEG over All Open PSD Files.jsx
v1.1 - 7th May 2023, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/help-loading-images-into-layers-by-filename/td-p/13769691
Notes:
All open files should have been previously saved, unsaved files may interrupt the batch processing
JPEG file names must match the open PSD name, with the addition of "_retouched.jpg" at the end of the doc name
*/

#target photoshop

if (app.documents.length > 0) {
    (function () {
        var jpgFolder = Folder.selectDialog('Please select the retouched JPEG folder:');
        if (jpgFolder === null) return;
        var savedDisplayDialogs = app.displayDialogs;
        app.displayDialogs = DialogModes.NO;
        while (app.documents.length > 0) {
                var psdName = activeDocument.name.replace(/\.[^\.]+$/, '');
                var jpgName = psdName + "_retouched.jpg";
                var jpgFile = jpgFolder + '/' + jpgName;
                placeFile(File(jpgFile), 100);
                activeDocument.activeLayer.rasterize(RasterizeType.ENTIRELAYER);
                activeDocument.close(SaveOptions.SAVECHANGES);
        }
        app.displayDialogs = savedDisplayDialogs;
        app.beep();
    })();
}
else {
    alert('One or more previously saved docs must be open to use this script!');
}

function placeFile(file, scale) {
    try {
        var idPlc = charIDToTypeID("Plc ");
        var desc2 = new ActionDescriptor();
        var idnull = charIDToTypeID("null");
        desc2.putPath(idnull, new File(file));
        var idFTcs = charIDToTypeID("FTcs");
        var idQCSt = charIDToTypeID("QCSt");
        var idQcsa = charIDToTypeID("Qcsa");
        desc2.putEnumerated(idFTcs, idQCSt, idQcsa);
        var idOfst = charIDToTypeID("Ofst");
        var desc3 = new ActionDescriptor();
        var idHrzn = charIDToTypeID("Hrzn");
        var idPxl = charIDToTypeID("#Pxl");
        desc3.putUnitDouble(idHrzn, idPxl, 0.000000);
        var idVrtc = charIDToTypeID("Vrtc");
        var idPxl = charIDToTypeID("#Pxl");
        desc3.putUnitDouble(idVrtc, idPxl, 0.000000);
        var idOfst = charIDToTypeID("Ofst");
        desc2.putObject(idOfst, idOfst, desc3);
        var idWdth = charIDToTypeID("Wdth");
        var idPrc = charIDToTypeID("#Prc");
        desc2.putUnitDouble(idWdth, idPrc, scale);
        var idHght = charIDToTypeID("Hght");
        var idPrc = charIDToTypeID("#Prc");
        desc2.putUnitDouble(idHght, idPrc, scale);
        var idAntA = charIDToTypeID("AntA");
        desc2.putBoolean(idAntA, true);
        executeAction(idPlc, desc2, DialogModes.NO);
    } catch (e) { }
}

 

 

Nancy OShea
Community Expert
May 4, 2023

I must have forgotten my jellyfish pills. I can't picture what you're trying to do.

 

OPTION 1:  Photoshop can make a contact sheet.

Go to File > Automate > Contact Sheet II > load images and sort by file name.

 

OPTION 2: Create a single file with multiple images stacked in layers.

File > Scripts > Load files into Stack. 

 

Nancy O'Shea— Product User & Community Expert
joshakatz
joshakatzAuthor
Known Participant
May 4, 2023

thank you for the reply, unfortunately neither of those 2 options are what I'm looking for.

 

I guess to try and make it more clear:

I have several images named IMG001.raf, Img002.raf etc and several coorisponding images named IMG001_retouched.jpg, IMG002_retouched.jpg etc.

 

I'm looking for a way to match the retouched files and layer them over the originals automatically, rather than one at a time by hand as I have been doing for days now.

Stephen Marsh
Community Expert
May 4, 2023

@joshakatz – A script could possibly help here... As these are raw files, they will open into ACR first, so to successfully layer them it would be best to batch save the raw files as TIFF or PSD first, then use a script to match up the files. One would then either have the input files in a single folder, or in two separate input folders for the script to process.

 

Can you explain step by step your workflow with the .raf files and the .jpg files?