Name
tell end [tell]
Syntax
Tell app "SoundJam MP" (* code statements *) end tell
Description
The tell
compound statement identifies the target
of an AppleScript command or Apple event (as in tell app "Photoshop 5.5"
) followed by other AppleScript statements
and an end tell
. The tell
compound statement can enclose any number of AppleScript statements,
including other tell
statements and flow-control
structures such as if
or
repeat
. You can identify any object in a
tell
statement, but unless the object is an
application
object such as FileMaker Pro or
QuarkXPress, it has to be nested within another
tell
statement targeting the
object’s parent application. For example, if you
want to use a statement such as:
tell window 1 to close
then you would have to first target the application that “owns” the window, as in the following example:
tell application "BBEdit 5.0" (* hasChanged will be true or false *) set hasChanged to (front window's modified) if hasChanged then tell front window to close saving yes else tell front window to close end if end tell
This script first finds out whether the front BBEdit window has been
modified, and it stores this boolean
value
(true
or false
) in the
hasChanged
variable. If true
,
then a tell
simple statement sends the front
BBEdit window a close command (with a parameter
instructing BBEdit to save the changes). If this
tell
statement was not nested within the
tell app "BBEdit"...
statement, then AppleScript would not know which application’s window the script ...
Get AppleScript in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.