title: Applescript open file with TextEdit and export them as pdf
body: <p>This is my very first applescript. I use automator to launch the script as 
  I drop new files to a folder (Folder action).</p>
  
  <p>In Automator I have 2 action: 
  1- Get Specified Finder Items
  2- The Apple Script</p>
  
  <p>But I can't make it running. The script stops without warning after opening the files.</p>
  
  <p>Here is the script:</p>
  
  <pre><code>on run {input, parameters}
  
  tell application "TextEdit" to activate
  
  repeat with theFile in input
  
      set theFilePath to theFile as alias
  
      tell application "TextEdit" to open theFilePath
  
      tell application "System Events"
          tell process "TextEdit"
              set foremost to true
              click menu item "Export as PDF..." of menu "File" of menu bar 1
              click button "Save"
              click menu item "Close" of menu "File" of menu bar 1
          end tell
      end tell
  
  end repeat
  
  return input
  end run
  </code></pre>
  
  <p>Can anyone help me on this?</p>
  
  <p>I just want to export all the files in the specified folders to pdf using TextEdit.</p>
  
  <p>Thanks</p>