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
0
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!
 

DingusDude

New Member
Messages
4
Likes
0
Apologies, I think I found a script on here from User @MrToM!

 

MrToM

Guru
Messages
3,595
Likes
3,321
I PM'd you, or replied in the converstaion, or whatever it's called these days.....jeeze.

Regards.
MrToM.
 

MarshySwamp

Active Member
Messages
34
Likes
10
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!');
    }
}());
 

DingusDude

New Member
Messages
4
Likes
0
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!
 

MarshySwamp

Active Member
Messages
34
Likes
10
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?
 

DingusDude

New Member
Messages
4
Likes
0
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!
 

thebestcpu

Guru
Messages
2,994
Likes
2,760
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
 

Top