@Laf Tasarim Ofisi
Give the following code a try...
The script will prompt you to select one or more TIFF files to open, bypassing the missing links dialog window...
Next, the script will then loop over the 3 named linked smart object layers, relinking them to the new asset based on the name of the parent directory.
So, the placeholder XXX design.psd will be relinked to BAHRAIN APPLE design.psd or ACAI design.psd etc. Same for the XXX obj.psd and XXX bg.psd placeholder files. All instances of the base three linked files of the same name will be updated.
The open file will then be saved and closed, before the next file is opened and the process is repeated until all selected files to open have been processed.
/*
Relink Named Smart Objects to Parent Folder.jsx
Stephen Marsh
v1.0, 27th November 2024
https://community.adobe.com/t5/photoshop-ecosystem-discussions/batch-processing-replace-linked-image/td-p/15000552
*/
#target photoshop;
// Skip the open dialog warnings
var savedDisplayDialogs = app.displayDialogs;
app.displayDialogs = DialogModes.NO;
// Hide the Photoshop panels
app.togglePalettes();
// Select multiple files to open (ignoring warnings)
var fileOrFiles = File.openDialog("Select the TIFF file/s to open:", Multiselect = true);
// Create the progress bar window
var win = new Window("palette", "Progress", [150, 150, 600, 270]);
var progressBar = win.add("progressbar", [20, 12, 430, 24], 0, fileOrFiles.length);
var progressText = win.add("statictext", [10, 30, 440, 48], "Processing files...");
progressText.alignment = "center";
win.center();
win.show();
// Loop over the selected files
for (var i = 0; i < fileOrFiles.length; i++) {
// Update the progress bar
progressBar.value = i + 1;
progressText.text = "Processing file " + (i + 1) + " of " + fileOrFiles.length;
win.update();
// Open the file and get the active document
var openFiles = app.open(File(fileOrFiles[i]));
// Set the doc path variables
var parentPath = app.activeDocument.path.fsName;
var fruitName = parentPath.replace(/(^.+\/)(.+$)/, "$2");
// Update the linked "design" smart objects
selectLayerByName("XXX design");
relinkToFile(parentPath + "/" + fruitName + " design.psd");
// Update the linked "obj" smart objects
selectLayerByName("XXX obj");
relinkToFile(parentPath + "/" + fruitName + " obj.psd");
// Update the linked "bg" smart objects
selectLayerByName("XXX bg");
relinkToFile(parentPath + "/" + fruitName + " bg.psd");
// End of link update alert
app.beep();
// Close and save
app.activeDocument.close(SaveOptions.SAVECHANGES);
}
// Close the progress bar window
app.bringToFront();
win.close();
// End of script alert
alert("Script completed!");
// Restore the Photoshop panels
app.togglePalettes();
app.displayDialogs = savedDisplayDialogs;
function selectLayerByName(layerName) {
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var list = new ActionList();
var reference = new ActionReference();
reference.putName(s2t("layer"), layerName);
descriptor.putReference(s2t("null"), reference);
descriptor.putBoolean(s2t("makeVisible"), false);
descriptor.putList(s2t("layerID"), list);
executeAction(s2t("select"), descriptor, DialogModes.NO);
}
function relinkToFile(filePath) {
var idplacedLayerRelinkToFile = stringIDToTypeID("placedLayerRelinkToFile");
var desc431 = new ActionDescriptor();
var idnull = stringIDToTypeID("null");
desc431.putPath(idnull, new File(filePath));
executeAction(idplacedLayerRelinkToFile, desc431, DialogModes.NO);
}
https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html
... View more