Advertisement
Cronos

Illustrator Word Count Script

Aug 27th, 2014
1,375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #target Illustrator
  2.  
  3. //  script.name = wordCount.jsx;
  4. //  script.description = counts words (and characters including spaces) in the active document
  5. //  script.requirements = an open document with some text
  6. //  script.parent = carlos canto // 08/27/2014
  7. //  script.elegant = false;
  8.  
  9. // Usage: The script targets all text in a document by default,
  10. //
  11. //               press and hold Ctrl/Cmd before running the script to process Selected text frames only
  12.  
  13.  
  14. function main () {
  15.     try {var idoc = app.activeDocument;}
  16.     catch (e) {alert ('open a document and try again'); return };
  17.    
  18.     var tfObj=idoc.textFrames;
  19.     var wordcount = 0;
  20.     var charcount = 0;
  21.     var linecount = 0;
  22.    
  23.     if(ScriptUI.environment.keyboardState.ctrlKey || ScriptUI.environment.keyboardState.metaKey) { // metaKey = cmd key on a mac
  24.         //alert('ctrl key');
  25.         var sel = idoc.selection;
  26.         tfObj = null;
  27.         tfObj = [];
  28.         for (t=0; t<sel.length; t++) {
  29.             var itext = sel[t];
  30.             if(itext.typename=="TextFrame")
  31.                 tfObj.push(itext);
  32.         }
  33.     }
  34.  
  35.     for (var i=0; i<tfObj.length; i++){
  36.         var tf = tfObj[i];
  37.  
  38.         wordcount += tf.words.length;
  39.         charcount += tf.characters.length; // includes spaces
  40.         linecount += tf.lines.length;
  41.     }
  42.  
  43.     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.';
  44.     alert('Word Count: ' + wordcount + '\rCharacter Count (including spaces): ' + charcount + '\rLine Count: ' + linecount + helpmsg);
  45.  
  46. } // end main function
  47.  
  48. main ();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement