Need to develop PS script to find folder with same name?

Discussion of Photoshop Scripting, Photoshop Actions and Photoshop Automation in General

Moderators: Tom, Kukurykus

jacks_bfa

Need to develop PS script to find folder with same name?

Post by jacks_bfa »

Dear Friends,

I working on mobile apps, In my psd there is too many folder. but I don't want to

repeat folder with same name.

if by mistake I creates such folder it should be focus or highlighted when I will

run the required script.

for e.g.

in my psd I creates below folder

"2","people","f_shape","c_palete","Background","people"

in this situation "people" should be focus or highlighted to warn me becase they

are 2 with same name.

Please help me

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

Paul MR

Need to develop PS script to find folder with same name?

Post by Paul MR »

You could try this...

Code: Select allmain();
function main(){
var layerSets = getLayerSetNames();
var str = layerSets.toString();
var Dups = new Array();
for(var a in layerSets){
var searchString= layerSets[a][1].toString();
var REX = new RegExp(searchString,'gi');
if(str.match(REX).length> 1) Dups.push(layerSets[a]);
}
if(Dups.length > 0){
deselectLayers();
for(var z in Dups){
    selectLayerById(Number(Dups[z][0]), true)
    }
}
};

function selectLayerById(ID, add) {
    add = (add == undefined)  ? add = false : add;
   var ref = new ActionReference();
   ref.putIdentifier(charIDToTypeID('Lyr '), ID);
   var desc = new ActionDescriptor();
   desc.putReference(charIDToTypeID('null'), ref);
   if (add) {
      desc.putEnumerated(stringIDToTypeID('selectionModifier'), stringIDToTypeID('selectionModifierType'), stringIDToTypeID('addToSelection'));
   }
   desc.putBoolean(charIDToTypeID('MkVs'), false);
   executeAction(charIDToTypeID('slct'), desc, DialogModes.NO);
};
function deselectLayers() {
    var desc01 = new ActionDescriptor();
        var ref01 = new ActionReference();
        ref01.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
    desc01.putReference( charIDToTypeID('null'), ref01 );
    executeAction( stringIDToTypeID('selectNoLayers'), desc01, DialogModes.NO );
};
function getLayerSetNames(){
   var ref = new ActionReference();
   ref.putEnumerated( charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
   var count = executeActionGet(ref).getInteger(charIDToTypeID('NmbL')) +1;
   var Names=[];
try{
    activeDocument.backgroundLayer;
var i = 0; }catch(e){ var i = 1; };
   for(i;i<count;i++){
       if(i == 0) continue;
        ref = new ActionReference();
        ref.putIndex( charIDToTypeID( 'Lyr ' ), i );
        var desc = executeActionGet(ref);
        var layerName = desc.getString(charIDToTypeID( 'Nm  ' ));
        var Id = desc.getInteger(stringIDToTypeID( 'layerID' ));
        if(layerName.match(/^<\/Layer group/) ) continue;
        var layerType = typeIDToStringID(desc.getEnumerationValue( stringIDToTypeID( 'layerSection' )));
        var isLayerSet =( layerType == 'layerSectionContent') ? false:true;
if(isLayerSet) Names.push([[Id],[layerName]]);
   };
return Names;
};
jacks_bfa

Need to develop PS script to find folder with same name?

Post by jacks_bfa »

wow! Paul
It's a great work, I was very excited to see result , You saved my lot of time.

one more thing I need to add in this script, if there is no group with same name in the psd then I have to get message like alert.
Paul MR

Need to develop PS script to find folder with same name?

Post by Paul MR »

Please try this..

Code: Select allmain();
function main(){
var layerSets = getLayerSetNames();
var str = layerSets.toString();
var Dups = new Array();
for(var a in layerSets){
var searchString= layerSets[a][1].toString();
var REX = new RegExp(searchString,'gi');
if(str.match(REX).length> 1) Dups.push(layerSets[a]);
}
if(Dups.length > 1){
deselectLayers();
for(var z in Dups){
    selectLayerById(Number(Dups[z][0]), true);
    }
}else{
    alert("There are no duplicate layerset names");
    }
};

function selectLayerById(ID, add) {
    add = (add == undefined)  ? add = false : add;
   var ref = new ActionReference();
   ref.putIdentifier(charIDToTypeID('Lyr '), ID);
   var desc = new ActionDescriptor();
   desc.putReference(charIDToTypeID('null'), ref);
   if (add) {
      desc.putEnumerated(stringIDToTypeID('selectionModifier'), stringIDToTypeID('selectionModifierType'), stringIDToTypeID('addToSelection'));
   }
   desc.putBoolean(charIDToTypeID('MkVs'), false);
   executeAction(charIDToTypeID('slct'), desc, DialogModes.NO);
};
function deselectLayers() {
    var desc01 = new ActionDescriptor();
        var ref01 = new ActionReference();
        ref01.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
    desc01.putReference( charIDToTypeID('null'), ref01 );
    executeAction( stringIDToTypeID('selectNoLayers'), desc01, DialogModes.NO );
};
function getLayerSetNames(){
   var ref = new ActionReference();
   ref.putEnumerated( charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
   var count = executeActionGet(ref).getInteger(charIDToTypeID('NmbL')) +1;
   var Names=[];
try{
    activeDocument.backgroundLayer;
var i = 0; }catch(e){ var i = 1; };
   for(i;i<count;i++){
       if(i == 0) continue;
        ref = new ActionReference();
        ref.putIndex( charIDToTypeID( 'Lyr ' ), i );
        var desc = executeActionGet(ref);
        var layerName = desc.getString(charIDToTypeID( 'Nm  ' ));
        var Id = desc.getInteger(stringIDToTypeID( 'layerID' ));
        if(layerName.match(/^<\/Layer group/) ) continue;
        var layerType = typeIDToStringID(desc.getEnumerationValue( stringIDToTypeID( 'layerSection' )));
        var isLayerSet =( layerType == 'layerSectionContent') ? false:true;
if(isLayerSet) Names.push([[Id],[layerName]]);
   };
return Names;
};
jacks_bfa

Need to develop PS script to find folder with same name?

Post by jacks_bfa »

Thanks Lot the script is complete now
jacks_bfa

Need to develop PS script to find folder with same name?

Post by jacks_bfa »

Can we find layers with same way
Paul MR

Need to develop PS script to find folder with same name?

Post by Paul MR »

Yes, this should find duplicate layer names...

Code: Select allmain();
function main(){
if(!documents.length) return;
var layerSets = getLayerSetNames();
var str = layerSets.toString();
var Dups = new Array();
for(var a in layerSets){
var searchString=layerSets[a][1].toString();
var REX = new RegExp("\\b+" + searchString + '\\b','gi');
try{
if(str.match(REX).length> 1){
    Dups.push(layerSets[a]);
    }
}catch(e){}
}
if(Dups.length > 1){
deselectLayers();
for(var z in Dups){
    selectLayerById(Number(Dups[z][0]), true);
    }
}else{
    alert("There are no duplicate layer names");
    }
};

function selectLayerById(ID, add) {
    add = (add == undefined)  ? add = false : add;
   var ref = new ActionReference();
   ref.putIdentifier(charIDToTypeID('Lyr '), ID);
   var desc = new ActionDescriptor();
   desc.putReference(charIDToTypeID('null'), ref);
   if (add) {
      desc.putEnumerated(stringIDToTypeID('selectionModifier'), stringIDToTypeID('selectionModifierType'), stringIDToTypeID('addToSelection'));
   }
   desc.putBoolean(charIDToTypeID('MkVs'), false);
   executeAction(charIDToTypeID('slct'), desc, DialogModes.NO);
};
function deselectLayers() {
    var desc01 = new ActionDescriptor();
        var ref01 = new ActionReference();
        ref01.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
    desc01.putReference( charIDToTypeID('null'), ref01 );
    executeAction( stringIDToTypeID('selectNoLayers'), desc01, DialogModes.NO );
};
function getLayerSetNames(){
   var ref = new ActionReference();
   ref.putEnumerated( charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
   var count = executeActionGet(ref).getInteger(charIDToTypeID('NmbL')) +1;
   var Names=[];
try{
    activeDocument.backgroundLayer;
var i = 0; }catch(e){ var i = 1; };
   for(i;i<count;i++){
       if(i == 0) continue;
        ref = new ActionReference();
        ref.putIndex( charIDToTypeID( 'Lyr ' ), i );
        var desc = executeActionGet(ref);
        var layerName = desc.getString(charIDToTypeID( 'Nm  ' ));
        var Id = desc.getInteger(stringIDToTypeID( 'layerID' ));
        if(layerName.match(/^<\/Layer group/) ) continue;
        var layerType = typeIDToStringID(desc.getEnumerationValue( stringIDToTypeID( 'layerSection' )));
        var isLayerSet =( layerType == 'layerSectionContent') ? false:true;
if(!isLayerSet) Names.push([[Id],[layerName]]);
   };
return Names;
};
jacks_bfa

Need to develop PS script to find folder with same name?

Post by jacks_bfa »

Yes, It is done. Thanks again