What's new
Photoshop Gurus Forum

Welcome to Photoshop Gurus forum. Register a free account today to become a member! It's completely free. Once signed in, you'll enjoy an ad-free experience and be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Copy all paths from JPEG and paste them into a PSD?


DingusDude

New Member
Messages
4
Likes
1
Hi All,

I have been searching around for this and I thought it would have been a common request. I have hundreds of JPEGs in a folder called 'JPEGs' and identical PSDs in a folder called 'PSDs'. I have sent out the JPEGs for pathing and I want to bring the paths from the JPEGs into the PSDs with the corresponding name. Is this possible?

Thanks!
 
Apologies, I think I found a script on here from User @MrToM!

 
I PM'd you, or replied in the converstaion, or whatever it's called these days.....jeeze.

Regards.
MrToM.
 
Here is my take:

JavaScript:
/*
Batch Copy Paths from JPEG to PSD Files - 2 Input Folders.jsx
v1.0 - Stephen Marsh, 1st March 2023
Batch processing added to the following base script:
https://www.photoshopgurus.com/forum/threads/script-error-in-ps-2021.72619/
*/

#target photoshop

(function () {
    if (app.documents.length === 0) {
        try {
            // JPG input folder
            var folder1 = Folder.selectDialog("Select the JPEG folder:");
            if (folder1 === null) {
                alert('Script cancelled!');
                return;
            }
            // PSD input folder
            var folder2 = Folder.selectDialog("Select the PSD folder:");
            if (folder2 === null) {
                alert('Script cancelled!');
                return;
            }
            // Validate input folder selection
            var validateInputDir = (folder1.fsName === folder2.fsName);
            if (validateInputDir === true) {
                alert("Script cancelled as both the input folders are the same!");
                return;
            }
            // Limit the file input to jpg/jpeg
            var list1 = folder1.getFiles(/\.(jpg|jpeg)$/i);
            var list2 = folder2.getFiles(/\.(psd)$/i);
            // Alpha-numeric sort
            list1.sort();
            list2.sort();
            // Validate that folder 1 & 2 lists are not empty
            var validateEmptyList = (list1.length > 0 && list2.length > 0);
            if (validateEmptyList === false) {
                alert("Script cancelled as one of the input folders is empty!");
                return;
            }
            // Validate that the item count in folder 1 & 2 matches
            var validateListLength = (list1.length === list2.length);
            if (validateListLength === false) {
                alert("Script cancelled as the input folders don't have equal quantities of images!");
                return;
            }
            // Select the output folder
            var outputFolder = Folder.selectDialog("Please select the output folder...");
            if (outputFolder === null) {
                // alert('Script cancelled!');
                return;
            }
            // or
            /*
            // Create the output sub-directory
            var outputFolder = Folder(decodeURI(inputFolder + '/Paths Copied to PSD Files'));
            if (!outputFolder.exists) outputFolder.create();
            */
            // Save and set the dialog display settings
            var savedDisplayDialogs = app.displayDialogs;
            app.displayDialogs = DialogModes.NO;
            // Start the file processing counter at zero
            var counter = 0;
            // Perform the processing
            for (var i = 0; i < list1.length; i++) {
                open(list1[i]);
                open(list2[i]);
                //  Set the name of the save doc without extension
                var docName = app.documents[1].name.replace(/\.[^\.]+$/, '');
                // JPEG alphabetically sorts first [0]
                var sourceDoc = app.documents[0];
                // PSD alphabetically sorts second [1]
                var destinationDoc = app.documents[1];
                // Set the JPEG file as the active doc
                app.activeDocument = sourceDoc;
                // Get the first/top path from the JPEG file
                sourceDoc.pathItems[0].select();
                // Copy the selected path
                var copyPathItem = charIDToTypeID("copy");
                executeAction(copyPathItem, undefined, DialogModes.NO);
                // Set the active doc as the rendered Raw file
                app.activeDocument = destinationDoc;
                // Paste the copied path to destination file
                var pastePathItem = charIDToTypeID("past");
                executeAction(pastePathItem, undefined, DialogModes.NO);
                /*
                // Set the path to a clipping path
                activeDocument.pathItems[0].select();
                activeDocument.pathItems[0].makeClippingPath();
                */
                // Close the JPEG file without saving any changes
                sourceDoc.close(SaveOptions.DONOTSAVECHANGES);
                // Set the save path options and save the rendered Raw file as PSD
                var saveFile = File(outputFolder + "/" + docName + ".psd");
                savePSD(saveFile);
                // Close open files
                while (app.documents.length) {
                    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
                }
                // Increment the file processing counter for each loop
                counter++;

                function savePSD(saveFile) {
                    psdSaveOptions = new PhotoshopSaveOptions();
                    psdSaveOptions.embedColorProfile = true;
                    psdSaveOptions.alphaChannels = true;
                    psdSaveOptions.layers = true;
                    app.activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);
                }

            }
            app.displayDialogs = savedDisplayDialogs;
            // End of script notification
            app.beep();
            alert('Script completed!' + '\r' + counter + ' files saved to:' + '\r' + outputFolder.fsName);
            // outputFolder.execute();

        } catch (error) {
            while (app.documents.length > 0) {
                app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
            }
            alert("An unexpected error has occurred!");
        }
    } else {
        alert('Please close all open documents before running this script!');
    }
}());
 
Here is my take:

JavaScript:
/*
Batch Copy Paths from JPEG to PSD Files - 2 Input Folders.jsx
v1.0 - Stephen Marsh, 1st March 2023
Batch processing added to the following base script:
https://www.photoshopgurus.com/forum/threads/script-error-in-ps-2021.72619/
*/

#target photoshop

(function () {
    if (app.documents.length === 0) {
        try {
            // JPG input folder
            var folder1 = Folder.selectDialog("Select the JPEG folder:");
            if (folder1 === null) {
                alert('Script cancelled!');
                return;
            }
            // PSD input folder
            var folder2 = Folder.selectDialog("Select the PSD folder:");
            if (folder2 === null) {
                alert('Script cancelled!');
                return;
            }
            // Validate input folder selection
            var validateInputDir = (folder1.fsName === folder2.fsName);
            if (validateInputDir === true) {
                alert("Script cancelled as both the input folders are the same!");
                return;
            }
            // Limit the file input to jpg/jpeg
            var list1 = folder1.getFiles(/\.(jpg|jpeg)$/i);
            var list2 = folder2.getFiles(/\.(psd)$/i);
            // Alpha-numeric sort
            list1.sort();
            list2.sort();
            // Validate that folder 1 & 2 lists are not empty
            var validateEmptyList = (list1.length > 0 && list2.length > 0);
            if (validateEmptyList === false) {
                alert("Script cancelled as one of the input folders is empty!");
                return;
            }
            // Validate that the item count in folder 1 & 2 matches
            var validateListLength = (list1.length === list2.length);
            if (validateListLength === false) {
                alert("Script cancelled as the input folders don't have equal quantities of images!");
                return;
            }
            // Select the output folder
            var outputFolder = Folder.selectDialog("Please select the output folder...");
            if (outputFolder === null) {
                // alert('Script cancelled!');
                return;
            }
            // or
            /*
            // Create the output sub-directory
            var outputFolder = Folder(decodeURI(inputFolder + '/Paths Copied to PSD Files'));
            if (!outputFolder.exists) outputFolder.create();
            */
            // Save and set the dialog display settings
            var savedDisplayDialogs = app.displayDialogs;
            app.displayDialogs = DialogModes.NO;
            // Start the file processing counter at zero
            var counter = 0;
            // Perform the processing
            for (var i = 0; i < list1.length; i++) {
                open(list1[i]);
                open(list2[i]);
                //  Set the name of the save doc without extension
                var docName = app.documents[1].name.replace(/\.[^\.]+$/, '');
                // JPEG alphabetically sorts first [0]
                var sourceDoc = app.documents[0];
                // PSD alphabetically sorts second [1]
                var destinationDoc = app.documents[1];
                // Set the JPEG file as the active doc
                app.activeDocument = sourceDoc;
                // Get the first/top path from the JPEG file
                sourceDoc.pathItems[0].select();
                // Copy the selected path
                var copyPathItem = charIDToTypeID("copy");
                executeAction(copyPathItem, undefined, DialogModes.NO);
                // Set the active doc as the rendered Raw file
                app.activeDocument = destinationDoc;
                // Paste the copied path to destination file
                var pastePathItem = charIDToTypeID("past");
                executeAction(pastePathItem, undefined, DialogModes.NO);
                /*
                // Set the path to a clipping path
                activeDocument.pathItems[0].select();
                activeDocument.pathItems[0].makeClippingPath();
                */
                // Close the JPEG file without saving any changes
                sourceDoc.close(SaveOptions.DONOTSAVECHANGES);
                // Set the save path options and save the rendered Raw file as PSD
                var saveFile = File(outputFolder + "/" + docName + ".psd");
                savePSD(saveFile);
                // Close open files
                while (app.documents.length) {
                    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
                }
                // Increment the file processing counter for each loop
                counter++;

                function savePSD(saveFile) {
                    psdSaveOptions = new PhotoshopSaveOptions();
                    psdSaveOptions.embedColorProfile = true;
                    psdSaveOptions.alphaChannels = true;
                    psdSaveOptions.layers = true;
                    app.activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);
                }

            }
            app.displayDialogs = savedDisplayDialogs;
            // End of script notification
            app.beep();
            alert('Script completed!' + '\r' + counter + ' files saved to:' + '\r' + outputFolder.fsName);
            // outputFolder.execute();

        } catch (error) {
            while (app.documents.length > 0) {
                app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
            }
            alert("An unexpected error has occurred!");
        }
    } else {
        alert('Please close all open documents before running this script!');
    }
}());
Hi, sorry for just getting back to you. I did test this out and, for me at least, it only copies over the first out of three paths from the JPGs to the PSDs. Wanted to give you feedback!
 
Hi, sorry for just getting back to you. I did test this out and, for me at least, it only copies over the first out of three paths from the JPGs to the PSDs. Wanted to give you feedback!

That is by design, as I didn't know that you had multiple paths.

JavaScript:
// Get the first/top path from the JPEG file

Will you *always* have 3 paths in each file, or could this vary, sometimes 1, sometimes 2 or more etc?
 
That is by design, as I didn't know that you had multiple paths.

JavaScript:
// Get the first/top path from the JPEG file

Will you *always* have 3 paths in each file, or could this vary, sometimes 1, sometimes 2 or more etc?
The path count will vary. But as I said above I’m using a script from user MrToM but still wanted to try yours out. I’m happy to test out a script though in case one breaks due to a software update. It’s always good to have options especially if a client is breathing down your neck!
 
HI @DingusDude

You may already have a solution with the scripts above yet there may be a simpler modification to make the complete JPEG clipping path added to the PSD file. I am assuming that the JPEG and PSD have the exact some pixel dimensions. Here are the steps

1) Load JPEG into a new document
2) Place embedded the PSD file (it will come in as a Smart Object)
3) With the embedded Smart Object use the Convert to Layers
4) Delete the first Layer that is the JPEG

With the above steps you will have the PSD file and the path from the JPEG will be there in the Path panel

Now there are a couple limitations with this approach I believe
1) If you needed a background Layer the above steps will not leave a background Layer. If that is needed you would have to take the extra step of jumping to the bottom Layer and converting it to a background Layer
2) When you use the Convert to Layers on the Smart Object that contains the PSD, it will preserve the Layers, Layer Masks and Vector Masks yet stand alone paths in the Path panel that were in the PSD file may not be preserved.

So with those limitations, you would need to batch the process (with simple script) and possibly do the rest in an Action.

Just another direction to consider
John Wheeler
 
The path count will vary. But as I said above I’m using a script from user MrToM but still wanted to try yours out. I’m happy to test out a script though in case one breaks due to a software update. It’s always good to have options especially if a client is breathing down your neck!

Apologies, I just stumbled over this old topic and realised that I never replied.

The two previous scripts were misnamed, they only batch copied the top/first pathItem[0] from the source to the destination documents.

This updated code will copy all paths, whether the count is 1, 2, 3 or more.

JavaScript:
/*
Batch Copy All Paths from JPEG to PSD Files - 2 Input Folders.jsx
v1.0 - Stephen Marsh, 21st April 2024
Batch processing added to the following base script:
https://www.photoshopgurus.com/forum/threads/script-error-in-ps-2021.72619/
*/

#target photoshop

    (function () {
        if (app.documents.length === 0) {
            try {
                // JPG input folder
                var folder1 = Folder.selectDialog("Select the JPEG folder:");
                if (folder1 === null) {
                    alert('Script cancelled!');
                    return;
                }
                // PSD input folder
                var folder2 = Folder.selectDialog("Select the PSD folder:");
                if (folder2 === null) {
                    alert('Script cancelled!');
                    return;
                }
                // Validate input folder selection
                var validateInputDir = (folder1.fsName === folder2.fsName);
                if (validateInputDir === true) {
                    alert("Script cancelled as both the input folders are the same!");
                    return;
                }
                // Limit the file input to jpg/jpeg
                var list1 = folder1.getFiles(/\.(jpg|jpeg)$/i);
                var list2 = folder2.getFiles(/\.(psd)$/i);
                // Alpha-numeric sort
                list1.sort();
                list2.sort();
                // Validate that folder 1 & 2 lists are not empty
                var validateEmptyList = (list1.length > 0 && list2.length > 0);
                if (validateEmptyList === false) {
                    alert("Script cancelled as one of the input folders is empty!");
                    return;
                }
                // Validate that the item count in folder 1 & 2 matches
                var validateListLength = (list1.length === list2.length);
                if (validateListLength === false) {
                    alert("Script cancelled as the input folders don't have equal quantities of images!");
                    return;
                }
                // Select the output folder
                var outputFolder = Folder.selectDialog("Please select the output folder...");
                if (outputFolder === null) {
                    // alert('Script cancelled!');
                    return;
                }
                // or
                /*
                // Create the output sub-directory
                var outputFolder = Folder(decodeURI(inputFolder + '/Paths Copied to PSD Files'));
                if (!outputFolder.exists) outputFolder.create();
                */
                // Save and set the dialog display settings
                var savedDisplayDialogs = app.displayDialogs;
                app.displayDialogs = DialogModes.NO;
                // Start the file processing counter at zero
                var counter = 0;
                // Perform the processing
                for (var i = 0; i < list1.length; i++) {
                    open(list1[i]);
                    open(list2[i]);
                    //  Set the name of the save doc without extension
                    var docName = app.documents[1].name.replace(/\.[^\.]+$/, '');
                    // JPEG alphabetically sorts first [0]
                    var sourceDoc = app.documents[0];
                    // PSD alphabetically sorts second [1]
                    var destinationDoc = app.documents[1];
                    // Set the JPEG file as the active doc
                    app.activeDocument = sourceDoc;
                    // Forwards loop over the paths
                    for (var i = 0; i < sourceDoc.pathItems.length; i++) {
                        // Backwards loop over the paths
                        //for (i = sourceDoc.pathItems.length - 1; i > -1; i--) {
                        // Set the active doc as the JPEG file
                        app.activeDocument = sourceDoc;
                        // Select the path
                        thePath = sourceDoc.pathItems[i];
                        thePath.select();
                        // Copy the selected path
                        var copyPathItem = charIDToTypeID("copy");
                        executeAction(copyPathItem, undefined, DialogModes.NO);
                        // Set the active doc as the PSD file
                        app.activeDocument = destinationDoc;
                        // Paste the copied path to destination file
                        // NOTE: Clipping paths settings aren't retained!
                        var pastePathItem = charIDToTypeID("past");
                        executeAction(pastePathItem, undefined, DialogModes.NO);
                        // Deselect the paths
                        destinationDoc.pathItems[0].deselect();
                        /*
                        // Deselect the paths
                        function s2t(s) {
                            return app.stringIDToTypeID(s);
                        }
                        var descriptor = new ActionDescriptor();
                        var reference = new ActionReference();
                        reference.putEnumerated(s2t("path"), s2t("ordinal"), s2t("targetEnum"));
                        descriptor.putReference(s2t("null"), reference);
                        executeAction(s2t("deselect"), descriptor, DialogModes.NO);
                        */
                    }
                    // Close the JPEG file without saving any changes
                    sourceDoc.close(SaveOptions.DONOTSAVECHANGES);
                    // Set the save path options and save the rendered Raw file as PSD
                    var saveFile = File(outputFolder + "/" + docName + ".psd");
                    savePSD(saveFile);
                    // Close open files
                    while (app.documents.length) {
                        app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
                    }
                    // Increment the file processing counter for each loop
                    counter++;

                    function savePSD(saveFile) {
                        psdSaveOptions = new PhotoshopSaveOptions();
                        psdSaveOptions.embedColorProfile = true;
                        psdSaveOptions.alphaChannels = true;
                        psdSaveOptions.layers = true;
                        app.activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);
                    }

                }
                app.displayDialogs = savedDisplayDialogs;
                // End of script notification
                app.beep();
                alert('Script completed!' + '\r' + counter + ' files saved to:' + '\r' + outputFolder.fsName);
                // outputFolder.execute();

            } catch (e) {
                while (app.documents.length > 0) {
                    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
                }
                //alert("An unexpected error has occurred!");
                alert("Error!" + "\r" + e + ' ' + e.line);
            }
        } else {
            alert('Please close all open documents before running this script!');
        }
    }());
 
The following 1.1 updated version of my previous script will retain the Clipping Path setting from the JPEG file to the PSD (however the flatness value isn't known and is blank).

JavaScript:
/*
Batch Copy All Paths from JPEG to PSD Files - 2 Input Folders.jsx
v1.0 - 21st April 2024: Stephen Marsh
v1.1 - 28th April 2024: Fixed the issue of the nominated clipping path being lost when pasted
Batch processing added to the following base script:
https://www.photoshopgurus.com/forum/threads/script-error-in-ps-2021.72619/
*/

#target photoshop

    (function () {
        if (app.documents.length === 0) {
            try {
                // JPG input folder
                var folder1 = Folder.selectDialog("Select the source JPEG folder containing the paths:");
                if (folder1 === null) {
                    alert('Script cancelled!');
                    return;
                }
                // PSD input folder
                var folder2 = Folder.selectDialog("Select the target PSD folder to copy the paths to:");
                if (folder2 === null) {
                    alert('Script cancelled!');
                    return;
                }
                // Validate input folder selection
                var validateInputDir = (folder1.fsName === folder2.fsName);
                if (validateInputDir === true) {
                    alert("Script cancelled as both the input folders are the same!");
                    return;
                }
                // Limit the file input to jpg/jpeg
                var list1 = folder1.getFiles(/\.(jpg|jpeg)$/i);
                var list2 = folder2.getFiles(/\.(psd)$/i);
                // Alpha-numeric sort
                list1.sort();
                list2.sort();
                // Validate that folder 1 & 2 lists are not empty
                var validateEmptyList = (list1.length > 0 && list2.length > 0);
                if (validateEmptyList === false) {
                    alert("Script cancelled as one of the input folders is empty!");
                    return;
                }
                // Validate that the item count in folder 1 & 2 matches
                var validateListLength = (list1.length === list2.length);
                if (validateListLength === false) {
                    alert("Script cancelled as the input folders don't have equal quantities of images!");
                    return;
                }
                // Select the output folder
                var outputFolder = Folder.selectDialog("Please select the output folder to save to:");
                if (outputFolder === null) {
                    // alert('Script cancelled!');
                    return;
                }
                // or
                /*
                // Create the output sub-directory
                var outputFolder = Folder(decodeURI(inputFolder + '/Paths Copied to PSD Files'));
                if (!outputFolder.exists) outputFolder.create();
                */
                // Save and set the dialog display settings
                var savedDisplayDialogs = app.displayDialogs;
                app.displayDialogs = DialogModes.NO;
                // Start the file processing counter at zero
                var counter = 0;
                // Perform the processing
                for (var i = 0; i < list1.length; i++) {
                    open(list1[i]);
                    open(list2[i]);
                    //  Set the name of the save doc without extension
                    var docName = app.documents[1].name.replace(/\.[^\.]+$/, '');
                    // JPEG alphabetically sorts first [0]
                    var sourceDoc = app.documents[0];
                    // PSD alphabetically sorts second [1]
                    var destinationDoc = app.documents[1];
                    // Set the JPEG file as the active doc
                    app.activeDocument = sourceDoc;
                    // Forwards loop over the paths
                    for (var i = 0; i < sourceDoc.pathItems.length; i++) {
                        // Backwards loop over the paths
                        //for (i = sourceDoc.pathItems.length - 1; i > -1; i--) {
                        // Set the active doc as the JPEG file
                        app.activeDocument = sourceDoc;
                        // Select the path
                        thePath = sourceDoc.pathItems[i];
                        thePath.select();
                        // Copy the selected path
                        var copyPathItem = charIDToTypeID("copy");
                        executeAction(copyPathItem, undefined, DialogModes.NO);
                        // Check for a clipping path
                        if (app.activeDocument.pathItems[i].kind === PathKind.CLIPPINGPATH) {
                            var clippingPath = app.activeDocument.pathItems[i].name;
                        }
                        // Set the active doc as the PSD file
                        app.activeDocument = destinationDoc;
                        // Paste the copied path to destination file
                        var pastePathItem = charIDToTypeID("past");
                        executeAction(pastePathItem, undefined, DialogModes.NO);
                        // Deselect the paths
                        destinationDoc.pathItems[0].deselect();
                        /*
                        // Deselect the paths
                        function s2t(s) {
                            return app.stringIDToTypeID(s);
                        }
                        var descriptor = new ActionDescriptor();
                        var reference = new ActionReference();
                        reference.putEnumerated(s2t("path"), s2t("ordinal"), s2t("targetEnum"));
                        descriptor.putReference(s2t("null"), reference);
                        executeAction(s2t("deselect"), descriptor, DialogModes.NO);
                        */
                    }
                    // Close the JPEG file without saving any changes
                    sourceDoc.close(SaveOptions.DONOTSAVECHANGES);
                    // Set the clipping path
                    app.activeDocument.pathItems.getByName(clippingPath).makeClippingPath();
                    // Set the save path options and save the rendered Raw file as PSD
                    var saveFile = File(outputFolder + "/" + docName + ".psd");
                    savePSD(saveFile);
                    // Close open files
                    while (app.documents.length) {
                        app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
                    }
                    // Increment the file processing counter for each loop
                    counter++;

                    function savePSD(saveFile) {
                        psdSaveOptions = new PhotoshopSaveOptions();
                        psdSaveOptions.embedColorProfile = true;
                        psdSaveOptions.alphaChannels = true;
                        psdSaveOptions.layers = true;
                        app.activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);
                    }

                }
                app.displayDialogs = savedDisplayDialogs;
                // End of script notification
                app.beep();
                alert('Script completed!' + '\r' + counter + ' files saved to:' + '\r' + outputFolder.fsName);
                // outputFolder.execute();

            } catch (e) {
                while (app.documents.length > 0) {
                    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
                }
                //alert("An unexpected error has occurred!");
                alert("Error!" + "\r" + e + ' ' + e.line);
            }
        } else {
            alert('Please close all open documents before running this script!');
        }
    }());
 

Back
Top