Can a script count how many lines, words and characters there is in a Text Layer?
I've been browsing here and I found this script that counts the words and characters in a text layer, but it can't count how many lines there is in it. I've found other scripts that should count the lines but they didn't work.
So is it possible to add a line counter in the selected text layer?
Also, how would I add a line in the code that breaks the line (add an enter) at a specific point, for example, breaks the line in the second word of the text layer, or the forth word, I'm asking because this would help me too.
Image example:

//
/*
<javascriptresource>
<name>Count Words and Characters</name>
</javascriptresource>
*/
function run()
{
var layer = activeDocument.activeLayer;
if (layer.kind == LayerKind.TEXT)
{
var words = layer.textItem.contents;
words = words.replace(/(\r\n|\n|\r)/gm," ");
var countwords = words.split(" ").length;
var countletters = words.split(" ").join(" ").length;
alert("\n " + countwords + " Words\n " + countletters + " Characters","Count");
}
else
{
alert("Select a text layer.","Count");
}
}
run();
