beautypg.com

Apple AppleScript Finder Guide User Manual

Page 15

background image

C H A P T E R 1

Introduction to Finder Scripting

What Is Finder Scripting?

3

tell application "Finder"

copy items of folder "AppleScript" of folder "Projects" of ¬

startup disk to folder "Backups" of disk "Storage"

end tell

This script consists of a three-line Tell statement that names the Finder applica-

tion running on the local computer as the target application. (The ¬ symbol

is a “soft” return; it tells AppleScript to treat the line it’s on and the line that

follows as if they are a single line.) As far as AppleScript is concerned, the

Finder is just like any other scriptable application.
Like other scriptable applications, the Finder defines commands that you

can use in scripts to describe actions. Some of these are standard application

commands, such as Copy, Open, Print, and Move, that can be used with most

scriptable applications. Others are commands unique to the Finder, such as

Eject, Put Away, and Restart. The Finder also defines classes of objects on which

actions can be performed, such as files, folders, and disks. Most of these object

classes are unique to the Finder.
The copy command in the preceding example acts on the objects described by

the reference items of folder "AppleScript" of folder "Projects"
of startup disk

. The folder AppleScript is located at the top level of the

folder Projects, which located at the top level of the startup disk. The term
items

refers to all objects in the AppleScript folder, including files, other folders,

suitcases, and so on. Any object in the Finder can be identified from within

a script as long as its container and if necessary the container’s containers

are also identified.
By using AppleScript features such as Repeat statements and other control

statements, you can create more complex scripts that take different actions

depending on the outcome of one or more tests. For example, the script that

follows checks all the disks of a specified computer for the presence of a folder

called Back Me Up. Whenever a disk contains such a folder, the script creates

a folder on a storage volume and copies the contents of Back Me Up to that

folder. (The storage volume must be mounted on the remote computer for this

script to work correctly.)