beautypg.com

Apple AppleScript Finder Guide User Manual

Page 16

background image

C H A P T E R 1

Introduction to Finder Scripting

4

What Is Finder Scripting?

tell application "Finder" of machine "Macintosh IIci"

repeat with i in every disk in desktop

if folder "Back Me Up" of i exists then

set folderName to name of i & " " & ¬

day of (current date) & " " & time of (current date)

set newFolder to make folder at ¬

disk "Storage" with properties {name:folderName}

duplicate (items of folder "Back Me Up" of i) to newFolder

end if

end repeat

end tell

The Repeat statement in this script applies the statements it contains to every

disk on the desktop of the computer named Macintosh IIci. The If statement

within the Repeat statement checks each disk for the presence of a folder called

Back Me Up. If the folder exists on a disk, the second line of the If statement

sets the variable folderName to a string that consists of the disk’s name,

the day of the month, and the time in seconds since the beginning of that day,

thus ensuring that any other backup folders created from the same disk at a

different time will have slightly different names. The rest of the If statement

creates a new folder with the name assigned to folderName on a storage disk

and asks the Finder to duplicate the items in the Back Me Up folder to the

new folder.
As you can see, scripts that control the Finder use familiar terms like folder,
disk

, and desktop as well as standard AppleScript terms like of, repeat,

and tell. Chapter 2, “Finder Objects,” describes all the terms the Finder

defines for objects, and Chapter 3, “Finder Commands,” describes the terms

it defines for commands. You can use these chapters as references when you

need detailed information about specific objects or commands. However, the

easiest way to learn how to use the scripting terminology defined by the Finder

is to record your actions in the Finder and examine the resulting script.
The next section describes how to use record and edit scripts that control the

Finder. When you see how the Finder uses its own terminology in recorded

scripts, you can begin writing your own scripts from scratch.