O'Reilly logo

AppleScript in a Nutshell by Bruce W. Perry

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required