Copy link to clipboard
Copied
Hello,
I have all my work outsourced for clipping paths but to cut down on download times we work with jpgs. Unfortunately I spend quite a lot of time transferring those clipping paths back to the corresponding raw files once I get the jpgs back. I've seen similar posts about this before but wasnt sure whether scripts are version specific to photoshop. Any help would be appreciated here on how I can acquire a script that can batch transfer the clipping paths back to the raw files. Thanks.
Copy link to clipboard
Copied
(2) Apart from the extension, does the rest of base filename match?
ABC_123.jpg
ABC_123.nef
(3) Are both sets of files in the same folder or are they in separate folders?
(4) Are you saving as PSD or something else?
Edit: Start with the following script for single pairs... I'll add further modifications for batching an entire folder once you answer my four questions above:
https://www.photoshopgurus.com/forum/threads/script-error-in-ps-2021.72619/
I've seen similar posts about this before but wasnt sure whether scripts are version specific to photoshop.
Generally, scripts often work fine between different versions, sometimes older versions need some changes, it all depends.
If you have seen other scripts to do the same, please provide a link to them!
Copy link to clipboard
Copied
@SFlaneur415 – Are you still out there?
Copy link to clipboard
Copied
Hi Stephen,
Sorry for the late reply and I really appreciate all the help.
1. The raw file type extension is .ARW from my sony camera
2. Yes the base file names match
3. The files are in separate folders
4. I've been saving the files as .tif (lightroom default save).
I'll take a look at everything you've written and let you know if I have any questions. Thanks so much again for your help.
Copy link to clipboard
Copied
You should be able to use the second script posted:
Batch Copy Paths from JPEG to Raw Files - 2 Input Folders.jsx
Just perform a search/replace in a text editor replacing nef for arw – just be careful and change one instance at a time to ensure that only the appropriate code is being replaced, just in case nef appears as part of a longer word that doesn't need changing!
In the short term you can use the existing code to save PSD and then use a Batch action or Image Processor to convert the PSD to TIFF.
I'll post revised code to directly save to TIFF rather than PSD when I have time.
Copy link to clipboard
Copied
As there was no reply, I have assumed NEF, just change all references from NEF to ORF or whatever your raw camera file extension is. For the following script for files in a single folder, the JPEG file has to sort/open first with the raw file second. So if the raw file was a CR2, the order would have to be swapped around in the code, which is why I asked about the file extension name.
/*
Batch Copy Paths from JPEG to Raw Files - 1 Input Folder.jsx
v1.0 - Stephen Marsh, 2nd June 2022
https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-to-transfer-clipping-paths-from-proxy-jpgs-to-raw-files/td-p/12977771
Batch processing added to the following base script:
https://www.photoshopgurus.com/forum/threads/script-error-in-ps-2021.72619/
*/
#target photoshop
// Disable dialog display
var restoreDialogMode = app.displayDialogs;
app.displayDialogs = DialogModes.NO;
// Run the main script function
main();
function main() {
// Select the input directory
var inputFolder = Folder.selectDialog("Please select the input folder...");
if (inputFolder == null) {
// alert('Script cancelled!');
return;
}
// Get the JPEG and NEF files
var fileList = inputFolder.getFiles(/\.(jpg|NEF)$/i);
// Force alpha-numeric list sort
fileList.sort();
// Validate that the file list is not empty
var inputCount = fileList.length;
var folderSelection = (inputCount === 0);
if (folderSelection === true) {
inputFolder = Folder.selectDialog("No files found, please reselect the input folder...");
return;
}
// Set quantity
var setQty = 2;
// Validate the input count vs. output count - % modulus test courtesy of kukurykus
var cancelScript = !(inputCount % setQty);
// alert(inputCount + ' input files combined into sets of ' + setQty + ' will produce ' + inputCount / setQty + ' output files.');
if (cancelScript === false) {
alert('Script cancelled as the quantity of input files are not evenly divisible by the set quantity!');
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();
*/
// Start the file processing counter at zero
var counter = 0;
// Loop over the input files
while (fileList.length) {
// Open 2 files at a time
for (var a = 0; a < 2; a++) {
try {
app.open(fileList.pop());
} catch (e) {}
}
// Run the function to copy the clipping paths
copyPaths();
// Increment the file processing counter for each loop
counter++;
}
function copyPaths() {
try {
// Set the name of the save doc without extension
var docName = app.documents[1].name.replace(/\.[^\.]+$/, '');
// JPEG alphabetically sorts first [0]
var sourceDoc = documents[0];
// NEF alphabetically sorts second [1]
var destinationDoc = 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.ERROR);
// 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);
}
// Enable dialog display
app.displayDialogs = restoreDialogMode;
} catch (error) {
alert("An unexpected error occurred!");
}
function savePSD(saveFile) {
psdSaveOptions = new PhotoshopSaveOptions();
psdSaveOptions.embedColorProfile = true;
psdSaveOptions.alphaChannels = true;
psdSaveOptions.layers = true;
app.activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);
}
}
// End of script notification
app.beep();
alert('Script completed!' + '\r' + counter + ' files saved to:' + '\r' + outputFolder.fsName);
// outputFolder.execute();
}
Copy link to clipboard
Copied
The previous script assumed that the JPG and NEF camera files were in a single input folder, named the same and alphabetically sorting correctly in pairs.
This is still assumed and required, however, this script processes from two separate input folders, one folder for the JPG files and the other folder for the NEF files. This means that it doesn't matter what the raw file format extension is as it will always open as the second file. Of course, all references of NEF will need to be changed if this isn't your raw file extension:
/*
Batch Copy Paths from JPEG to Raw Files - 2 Input Folders.jsx
v1.0 - Stephen Marsh, 2nd June 2022
https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-to-transfer-clipping-paths-from-proxy-jpgs-to-raw-files/td-p/12977771
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;
}
// NEF input folder
var folder2 = Folder.selectDialog("Select the NEF 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(/\.(nef)$/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];
// NEF 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!');
}
}());
Copy link to clipboard
Copied
@SFlaneur415 – Here is the updated code for ARW and TIFF:
/*
Batch Copy Paths from JPEG to ARW Files Save As TIFF - 2 Input Folders.jsx
v1.0 - Stephen Marsh, 7th June 2022
https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-to-transfer-clipping-paths-from-proxy-jpgs-to-raw-files/td-p/12977771
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;
}
// ARW input folder
var folder2 = Folder.selectDialog("Select the ARW 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(/\.(arw)$/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 first [0]
var sourceDoc = app.documents[0];
// ARW 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 + ".tif");
saveTIFF(saveFile);
// Close open files
while (app.documents.length) {
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
// Increment the file processing counter for each loop
counter++;
function saveTIFF(saveFile) {
tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.embedColorProfile = true;
// ByteOrder.MACOS or ByteOrder.IBM
tiffSaveOptions.byteOrder = ByteOrder.IBM;
tiffSaveOptions.transparency = true;
tiffSaveOptions.layers = true;
tiffSaveOptions.layerCompression = LayerCompression.ZIP;
tiffSaveOptions.interleaveChannels = true;
tiffSaveOptions.alphaChannels = true;
tiffSaveOptions.annotations = true;
tiffSaveOptions.spotColors = true;
tiffSaveOptions.saveImagePyramid = false;
// NONE | JPEG | TIFFLZW | TIFFZIP
tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;
app.activeDocument.saveAs(saveFile, tiffSaveOptions, 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!');
}
}());