Thanks for that! But it is showing error when I make it as a string.can you please help me with the whole code?
// 2015, use it at your own risk;
#target "photoshop-70.032"
if (app.documents.length > 0) {
var theTexts = main ();
alert (count (theTexts.join("\n")));
};
////////////////////////////////////
function main () {
// the file;
var myDocument = app.activeDocument;
// get number of layers;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
// process the layers;
var theLayers = new Array;
for (var m = 0; m <= theNumber; m++) {
try {
var ref = new ActionReference();
ref.putIndex( charIDToTypeID( "Lyr " ), m);
var layerDesc = executeActionGet(ref);
var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
// if not layer group ;
if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" && isBackground != true) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
var hasText = layerDesc.hasKey(stringIDToTypeID("textKey"));
// if type layer;
if (hasText == true) {
var textDesc = layerDesc.getObjectValue(stringIDToTypeID('textKey'));
var theText = textDesc.getString(stringIDToTypeID("textKey"));
theLayers.push(theText)
}
}
}
catch (e) {};
};
return theLayers
};
////// count characters //////
function count (theString) {
var words = theString//layer.textItem.contents;
words = words.replace(/(\r\n|\n|\r)/gm," ");
////////////////////////////////////
// remove double spaces and space at the end;
while (words.indexOf(" ") != -1) {words = words.replace(" ", " ")};
var endSpace = /\s$/;
words = words.replace(endSpace, "");
////////////////////////////////////
var countwords = words.split(" ").length;
var countletters = words.split(" ").join(" ").length;
return ("\n " + countwords + " Words\n " + countletters + " Characters");
};