title: Working with Automator "Run Applescript" variables
body: <p>Request assistance with truncating/trimming a string in an automator action used to create text-to-speech audio files from a text selection ranging from 30 or so characters to 800+, which is too long for a file name.</p>
  
  <p>In short, I am trying to truncate a string to 30 characters and pass that to the "Text to Audio File" action as the file name.</p>
  
  <p>Basic workflow is:</p>
  
  <p>Select text
  Initiate following Automator Action via Services Menu</p>
  
  <ol>
  <li>"Set Value of Variable" to input (e.g. selected text) and define as TextToSpeech</li>
  <li>"Set Value of Variable" to input (e.g. selected text) and define as FileName</li>
  <li>"Get Value of Variable" FileName</li>
  <li><p>"Run AppleScript"</p>
  
  <pre><code>on run {input, parameters}
      set theResult to input as string
      set finalResult to input as string
      set txtLength to (length of theResult)
      if txtLength &gt; 30 then
          set finalResult to (characters 1 thru 30 of theResult) as string
      end if
      return finalResult
  end run
  </code></pre></li>
  <li><p>"Set Value of Variable" input (e.g. selected text) and define as FileName</p></li>
  <li>"Get Value of Variable" TextToSpeech</li>
  <li>"Text to Audio File" with Save As: set to "FileName" </li>
  <li>"Encode to MPEG Audio"</li>
  </ol>
  
  <p>Any assistance/suggestions is greatly appreciated!</p>
  
  <p>Regards,</p>
  
  <p>Zephyr</p>