Why won't my AppleScript run as a Service? I have a simple AppleScript that works exactly as expected when run on its own, ether as an app, directly from within ScriptDebugger or Script Editor, or as an element of an Automation from within Automator:



However, when I attempt to run this Automation as a Service, for example by saving it as a Service and running it from the Services menu



nothing happens. The Service fails to run whether I use a "Run AppleScript" action in Automator, or create an application from the script, and use a Launch Application action.

Why won't my AppleScript run as a Service, when it runs perfectly in all other circumstances?
This is weird, but I have seen at least three people on Apple Support Communities who had this problem when a of process "x" and a tell application "System Events" to are on the same line.

Try this.


on run {input, parameters}
  tell application "System Events"
      tell process "TextWrangler" to set visible to not visible
  end tell
end run