Applescript executing code it shouldn't

K, I have a little function I wrote to save captured output text to a TextEdit document (it’s a gui wrapper for a shell script)

the snippet is

on saveOutput(theOutput)
	set theReply to (button returned of (display dialog "Display Output?"))
	if theReply is "Ok" then
		display dialog "wtf"
		(*tell application "TextEdit"
			make document with properties {text:theOutput}
		end tell*)
	end if
end saveOutput

Ok, now the function is only called in an “on click theObject” block. And only occurs when a button is clicked. Fair enough.

I can verify that the code isn’t actually running…since the display dialog command never executes. However, if I uncomment the tell application “Finder” block when the program starts TextEdit is opened with a blank document.

Recomment the block, start the program…voila! No more TextEdit.

What gives?

Could it be that the presence fo a “Tell application” statement activates said application, even though the handler is not called?
What about trying “using terms from”, something like this:

property TextEditor : "TextEdit"

--put this section instead of your tell application "TextEdit"
using terms from application "TextEdit"
   tell application TextEditor
       -- script here
   end tell
end using terms from


That is correct, when Applescript encounters a “tell ‘some app’” statement, “some_app” is launched so that Applescript can access it’s dictionary.

Brad Bumgarner, CTA