Copy link to clipboard
Copied
Or would rather do it for selected grops , smart objects, layers and layer comps . I mean you select things and the script put their names in file keywords so you coould later search quickly for sertain things in your DAM
// add selected layers’ names to keywords;
// 2021, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
var theLayers = collectSelectedLayersBounds ();
var theKeywords = myDocument.info.keywords;
for (var m = 0; m < theLayers.length; m++) {
var thisName = theLayers[m][0];
var theCheck = true;
for (var n = 0; n < theKeywords.length; n++) {
if (thisName == theKeywords[n]) {theCheck = fal
...
Copy link to clipboard
Copied
Take a look here (all top-level layers, not selected layers)
And here:
Copy link to clipboard
Copied
Thanks a lot Stephen , neighter of those scripts do it for selected layers although . When doing it to all layers it creates a lot of senceless junk in keyword lists like layer1 coppy2 etc. My guess it would stress any DAM system with lots of junk keywords .
I wonder if it's possible to modify somehow to work for selected only . MAybe group names ?
Copy link to clipboard
Copied
// add selected layers’ names to keywords;
// 2021, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
var theLayers = collectSelectedLayersBounds ();
var theKeywords = myDocument.info.keywords;
for (var m = 0; m < theLayers.length; m++) {
var thisName = theLayers[m][0];
var theCheck = true;
for (var n = 0; n < theKeywords.length; n++) {
if (thisName == theKeywords[n]) {theCheck = false}
};
if (theCheck == true) {theKeywords.push(thisName)};
};
myDocument.info.keywords = theKeywords;
alert (myDocument.info.keywords.join("\n"));
};
////// collect bounds of selected layers //////
function collectSelectedLayersBounds () {
// set to pixels;
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// get selected layers;
var selectedLayers = new Array;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref);
if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){
desc = desc.getList( stringIDToTypeID( 'targetLayers' ));
var c = desc.count;
var selectedLayers = new Array();
// run through selected layers;
for(var i=0;i<c;i++){
try{activeDocument.backgroundLayer;
var theIndex = desc.getReference( i ).getIndex();
}catch(e){var theIndex = desc.getReference( i ).getIndex()+1 };
// get id for solid color layers;
try {
var ref = new ActionReference();
ref.putIndex( charIDToTypeID("Lyr "), theIndex );
var layerDesc = executeActionGet(ref);
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theIdentifier = layerDesc.getInteger(stringIDToTypeID ("layerID"));
var theBounds = layerDesc.getObjectValue(stringIDToTypeID("bounds"));
var theseBounds = [theBounds.getUnitDoubleValue(stringIDToTypeID("left")), theBounds.getUnitDoubleValue(stringIDToTypeID("top")), theBounds.getUnitDoubleValue(stringIDToTypeID("right")), theBounds.getUnitDoubleValue(stringIDToTypeID("bottom"))];
selectedLayers.push([theName, theIdentifier, theseBounds]);
} catch (e) {};
};
// if only one:
}else{
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var layerDesc = executeActionGet(ref);
try {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theIdentifier = layerDesc.getInteger(stringIDToTypeID ("layerID"));
var theBounds = layerDesc.getObjectValue(stringIDToTypeID("bounds"));
var theseBounds = [theBounds.getUnitDoubleValue(stringIDToTypeID("left")), theBounds.getUnitDoubleValue(stringIDToTypeID("top")), theBounds.getUnitDoubleValue(stringIDToTypeID("right")), theBounds.getUnitDoubleValue(stringIDToTypeID("bottom"))];
selectedLayers = [[theName, theIdentifier, theseBounds]]
} catch (e) {};
};
// reset;
app.preferences.rulerUnits = originalRulerUnits;
return selectedLayers;
};