Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #target Illustrator
- // script.name = wordCount.jsx;
- // script.description = counts words (and characters including spaces) in the active document
- // script.requirements = an open document with some text
- // script.parent = carlos canto // 08/27/2014
- // script.elegant = false;
- // Usage: The script targets all text in a document by default,
- //
- // press and hold Ctrl/Cmd before running the script to process Selected text frames only
- function main () {
- try {var idoc = app.activeDocument;}
- catch (e) {alert ('open a document and try again'); return };
- var tfObj=idoc.textFrames;
- var wordcount = 0;
- var charcount = 0;
- var linecount = 0;
- if(ScriptUI.environment.keyboardState.ctrlKey || ScriptUI.environment.keyboardState.metaKey) { // metaKey = cmd key on a mac
- //alert('ctrl key');
- var sel = idoc.selection;
- tfObj = null;
- tfObj = [];
- for (t=0; t<sel.length; t++) {
- var itext = sel[t];
- if(itext.typename=="TextFrame")
- tfObj.push(itext);
- }
- }
- for (var i=0; i<tfObj.length; i++){
- var tf = tfObj[i];
- wordcount += tf.words.length;
- charcount += tf.characters.length; // includes spaces
- linecount += tf.lines.length;
- }
- var helpmsg = '\r\rHelp: \rScript works on all text by default, press & hold \rCtrl/Cmd before launching the script \rto count selected text frames only.';
- alert('Word Count: ' + wordcount + '\rCharacter Count (including spaces): ' + charcount + '\rLine Count: ' + linecount + helpmsg);
- } // end main function
- main ();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement