Here is an updated 1.1 version of my previous script which will alert on every layer that is linked (one by one, I couldn't be bothered logging them all at the end in a single alert or log file).
/*
Selected Layers to New Smart Object via Copy.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/is-there-a-way-to-use-quot-new-smart-object-via-copy-quot-in-bulk/td-p/14096358
v1.1, 20th September 2023, Stephen Marsh
*/
#target photoshop
function main() {
// Save the current dialog display settings
var savedDisplayDialogs = app.displayDialogs;
app.displayDialogs = DialogModes.NO;
// Get the selected layers: courtesy of jazz-y
var s2t = stringIDToTypeID;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('targetLayersIDs'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var lrs = executeActionGet(r).getList(p),
sel = new ActionReference();
// Loop over the selected layers: courtesy of jazz-y
for (var i = 0; i < lrs.count; i++) {
sel.putIdentifier(s2t('layer'), p = lrs.getReference(i).getIdentifier(s2t('layerID')));
(r = new ActionReference()).putIdentifier(s2t('layer'), p);
(d = new ActionDescriptor()).putReference(s2t("target"), r);
executeAction(s2t('select'), d, DialogModes.NO);
// Linked SO conditional check courtesy of r-bin
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("smartObject"));
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var d = executeActionGet(r);
if (d.hasKey(stringIDToTypeID("smartObject"))) {
d = d.getObjectValue(stringIDToTypeID("smartObject"));
if (d.hasKey(stringIDToTypeID("link"))) {
alert('The smart object layer "' + activeDocument.activeLayer.name + '" is linked, not embedded!');
} else {
var embeddedSOlayer = activeDocument.activeLayer.name;
// Call the new smart object via copy function: courtesy fo c.pfaffenbichler
newSmartObjectViaCopy();
//alert('The embedded smart object layer "' + embeddedSOlayer + '" has been copied!');
}
}
}
// Finish the loop
// Restore the dialogs
app.displayDialogs = savedDisplayDialogs;
}
function newSmartObjectViaCopy() {
try {
var idplacedLayerMakeCopy = stringIDToTypeID("placedLayerMakeCopy");
executeAction(idplacedLayerMakeCopy, undefined, DialogModes.NO);
return app.activeDocument.activeLayer
} catch (e) {
alert(e)
}
}
// Single history stage undo
activeDocument.suspendHistory("Selected Layers to New Smart Object via Copy.jsx", "main()");
EDIT: This version logs the linked layers that were skipped to a text file on the desktop, rather than alerting each layer:
/*
Selected Layers to New Smart Object via Copy.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/is-there-a-way-to-use-quot-new-smart-object-via-copy-quot-in-bulk/td-p/14096358
v1.2, 27th December 2023, Stephen Marsh
*/
#target photoshop
function main() {
// Save the current dialog display settings
var savedDisplayDialogs = app.displayDialogs;
app.displayDialogs = DialogModes.NO;
// Log file setup
var logFile = new File("~/Desktop/Selected Layers to New Smart Object via Copy LOG.txt");
if (logFile.exists);
logFile.remove();
var os = $.os.toLowerCase().indexOf("mac") >= 0 ? "mac" : "windows";
if (os === "mac") {
logFileLF = "Unix";
} else {
logFileLF = "Windows";
}
var dateTime = new Date().toLocaleString();
logFile.open("w");
logFile.encoding = "UTF-8";
logFile.lineFeed = logFileLF;
logFile.write(dateTime + "\r" + "Document name: " + activeDocument.name + "\r" + "The following layers are linked and therefore skipped:" + "\r\r");
logFile.close();
// Get the selected layers: courtesy of jazz-y
var s2t = stringIDToTypeID;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('targetLayersIDs'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var lrs = executeActionGet(r).getList(p),
sel = new ActionReference();
// Loop over the selected layers: courtesy of jazz-y
for (var i = 0; i < lrs.count; i++) {
sel.putIdentifier(s2t('layer'), p = lrs.getReference(i).getIdentifier(s2t('layerID')));
(r = new ActionReference()).putIdentifier(s2t('layer'), p);
(d = new ActionDescriptor()).putReference(s2t("target"), r);
executeAction(s2t('select'), d, DialogModes.NO);
// Linked SO conditional check courtesy of r-bin
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("smartObject"));
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var d = executeActionGet(r);
if (d.hasKey(stringIDToTypeID("smartObject"))) {
d = d.getObjectValue(stringIDToTypeID("smartObject"));
if (d.hasKey(stringIDToTypeID("link"))) {
// Log the linked layers which were skipped
writeToLog();
} else {
var embeddedSOlayer = activeDocument.activeLayer.name;
// Call the new smart object via copy function: courtesy fo c.pfaffenbichler
newSmartObjectViaCopy();
}
}
}
// Finish the loop
// Restore the dialogs
app.displayDialogs = savedDisplayDialogs;
// Open the log file
logFile.execute();
///// FUNCTIONS /////
function writeToLog() {
logFile.open("a");
logFile.encoding = "UTF-8";
logFile.lineFeed = logFileLF;
logFile.write(activeDocument.activeLayer.name + "\r");
logFile.close();
}
function newSmartObjectViaCopy() {
try {
var idplacedLayerMakeCopy = stringIDToTypeID("placedLayerMakeCopy");
executeAction(idplacedLayerMakeCopy, undefined, DialogModes.NO);
return app.activeDocument.activeLayer;
} catch (e) {
alert(e);
}
}
}
// Single history stage undo
activeDocument.suspendHistory("Selected Layers to New Smart Object via Copy.jsx", "main()");