Hello and a newbie question

Dear all,
this is my very first post and would like to say hello to everybody.
I am just starting with AppleScript but I already think it is quite a powerful language.
About this I have a question.
When I just open this little script in ScriptEditor (not run, just open)

set running to false

if running then
    tell application "Safari"
    end tell
end if

automatically Safari is launched. Changing “Safari” to many other applications names leads to the same behavior but not for Terminal, Terminal is not opened. Why? Why is it launched an application when the script is just opened?

Thank you in advance
Gaetano

Model: Macbook
Browser: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en; rv:1.8.1.4pre) Gecko/20070409 Camino/1.1b+
Operating System: Mac OS X (10.4)

Hi Gaetano,

welcome to MacScripter.

To evaluate a tell block Script Editor must read the dictionary of the specific application,
and therefore it opens the app. Terminal.app has actually only one command (do script),
which is similar to the do shell script command of the Standard Scripting Additions and I think AppleScript knows that :wink:

Thank you StefanK for your kind answer.
Does it mean that it is not possible to use a tell block referring to a non-running application without launching it?

Gaetano

Model: Macbook
Browser: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en; rv:1.8.1.4pre) Gecko/20070409 Camino/1.1b+
Operating System: Mac OS X (10.4)

In most cases it’s not possible. Sending Apple Events to an application causes it to launch

Hi.

Just to clarify this: if the running script executes a ‘tell’ statement addressed to an application, or (probably) if it contains such a statement and is opened in Script Editor, the application will launch. The application won’t launch if the script’s simply run from Script Menu (or as an applet) and the ‘tell’ statement isn’t executed. For example:

tell application "System Events"
	-- If Safari's running, tell it to quit. (Otherwise, don't tell it and it won't launch.)
	if (application process "Safari" exists) then tell application "Safari" to quit
end tell

Yes Nigel, it matches my little experience in this field in everything but Automator.
If the script, in Script Editor, is saved as application, the application the tell statement is addressed to is opened only if the “tell” block is executed. Automator seems to deviate from this behavior: if I save a script as Automator applet, every application a “tell” block is addressed to is opened.