title: have an AppleScript Automator service to process all text if no text is selected
body: <p>I’m using <a href="http://gist.github.com/1616556" rel="nofollow">nslater's wonderful script</a> for counting words and characters in a selected block of text, but I need two enchancements:</p>
  
  <ol>
  <li><p><strong>have the script available even without text selected.</strong> Currently, when I pull up the list of available Services without a selection, the Service isn’t there (that’s logical, of course, but enhancement #2 would change things).</p></li>
  <li><p><strong>add a conditional behaviour to the script:</strong> if no text is selected, process <em>all</em> text, but if there is a selection, then only process the selected text.</p></li>
  </ol>
  
  <p>Here is <strong>nslater's</strong> script, which I pasted into Automator (I created the Service by following the steps in his commented instructions):</p>
  
  <pre><code># Word and Character Count service for Mac OS X
  #
  # Adds a Word and Character Count option to the text selection context menu in all apps
  #
  # Use Automator.app to create a new service, and then select the Run AppleScript action.
  # Paste this code in to the text box, and save as Word and Character Count. Now switch to
  # a new app, select some text, and open the context menu to find the new option.
  
  on run {input, parameters}
      tell application "System Events"
          set _appname to name of first process whose frontmost is true
      end tell
      set word_count to count words of (input as string)
      set character_count to count characters of (input as string)
      tell application _appname
          display alert "" &amp; word_count &amp; " words, " &amp; character_count &amp; " characters"
      end tell
      return input
  end run
  </code></pre>