DekGenius.com
Team LiB   Previous Section   Next Section
tell simple statement

Syntax

tell app "SoundJam MP" to run

Description

You use the tell statement to identify the target of an AppleScript command:

tell app "Photoshop 5.5" to run

In this case, run is the Photoshop application's command. The tell simple statement only takes up one line of code and does not need to be completed with an end tell. You use the reserved word tell, followed by a reference to an object, such as the application "Finder," then the reserved word to preceding the actual command that you want to send to the object. tell statements can be nested within each other, such as using a tell simple statement inside a compound tell statement (one that involves several lines of code and finishes with end tell).

Examples

This code tells the Finder to open Photoshop only if a certain amount of memory is available to the computer:

tell application "Finder"
   (* largest free block is converted from bytes to megabytes then rounded off
with the round scripting addition *)
   set freeMem to (round (largest free block / 1024 / 1024))
   if freeMem > 50 then (* only open PS if there is a free memory block >
   50 meg *)
      tell application "Adobe¬ Photoshop¬ 5.5" to activate (* tell simple 
      statement *)
   else
      display dialog¬
"Freemem = " & freeMem & " Not enough memory for gluttonous Photoshop!"
   end if
end tell

This example occurs within a compound tell statement that targets the Finder. If the largest free block property of the Finder (which identifies the largest free block of available RAM on the computer) exceeds 50MB, then Photoshop receives an activate command as part of a tell simple statement.

If you are running AppleScript 1.4 or higher, you can create easy-to- remember aliases to invoke your favorite apps with the tell statement. For example, create an alias file for the SoundJam MP application, name this alias "SJ," and then store it in startup disk:System Folder:Scripting Additions. Now, when your AppleScripts include the code: tell app "SJ" the enclosed code statements direct their Apple Events to SoundJam MP. This saves a lot of typing!

    Team LiB   Previous Section   Next Section