Online Book Reader

Home Category

AppleScript_ The Definitive Guide - Matt Neuburg [149]

By Root 1411 0
3). This chapter catalogues the built-in commands of the AppleScript language—those not described elsewhere in this book. AppleScript defines very few commands of its own, leaving it to other applications to extend the language by defining further verbs as necessary.

(For the syntax of a command, see "Event Handlers" in Chapter 9; on how to use a command, see Chapter 11. For set, copy, and get, see "Assignment and Retrieval" in Chapter 7. For run, see "Run Handler" in Chapter 8. For error, see "Errors" in Chapter 19.)

Application Commands


A few commands may be sent to applications to start them up, bring them to the front, and make them quit. An application does not have to be scriptable to obey them (see Table 20-1 and the discussion there).

Name

launch

Syntax

launch application

Description

Makes sure an application is running, without bringing it frontmost or making it perform any actions. This command is not commonly needed, because AppleScript, as it runs a script that targets an application locally, will automatically attempt to start up that application if it isn't running already (a good thing, since an application that isn't running can't receive any Apple events). Some applications, however, perform special actions when started up automatically in this way, such as opening a document or coming to the front. The launch command can be a way of running the application while avoiding these special actions, and there is no penalty for issuing it if the application is already running, as nothing will happen.

Name

activate

Syntax

activate application

Description

Brings an application frontmost.

Name

reopen

Syntax

reopen application

Description

Tells an application to behave as if it had been opened from the Finder. Some applications behave specially when told to do this. For example, in the case of the Finder, reopen makes a window open if no Finder windows are open at that moment; launch and activate don't.

Name

quit

Syntax

quit application

Description

Tells an application to quit.

Standard Commands


The standard commands are basic events that should be implemented by any scriptable application. The only standard command implemented by AppleScript itself is count (with strings, lists, and records; see Chapter 13).

The count command is implemented in an unusual way. The class represents the element that is to be counted; it is optional, and most users prefer the second or third formulation if it is to be specified. (So, one tends to say "count items of L" rather than "count L each item.") If it is not specified, then it is up to the target to supply a default element and count it. Users tend to be unconscious of this fact. For example, when you say "count s," where s is a string, you're probably not aware that AppleScript is reinterpreting this as "count s each character." That's because character is the default element for a string; you could also specify a different element ("count words of s"). This syntax is sometimes the cause of misunderstandings, especially when talking to some scriptable application. See "Repeat With... In" in Chapter 19.

Name

count

Syntax

count object[each class]

count every class of object count class-plural of object

Description

Reports the number of class elements of object.

Logging Commands


These commands have to do with the script editor application's logging window or pane. They control the generation of the AppleScript messages that this window or pane is "watching" while it is open.

Name

log

Syntax

log value

Description

If the event log pane or window is open, writes value to the log pane or window. This is useful for debugging. See Appendix A for an example.

Name

stop log, start log

Syntax

stop log

start log

Description

If the event log pane or window is open, disables and enables automatic logging of Apple events sent between applications; has no effect on the log command.

Only the old version of Script Editor (version 1.9), and Script

Return Main Page Previous Page Next Page

®Online Book Reader