Beginning AppleScript
Prev Topic: Introduction
Next Topic: The Chain of Command
--------------------------------------------------------------------------------
What is AppleScript?
Most Macintosh users don't realize that there is a powerful hidden interface to their computers. While we are all familiar with the unique Macintosh look and feel that characterizes the Mac graphical interface, many of us don't know there is another way to control our Macs.
You see, the Mac OS icons, buttons, menus, palettes and windows we use every day, are not the only way to control the actions of your computer. There is another interface to the Mac--a language interface. Every Macintosh, right out of the box, can be automated and controlled using AppleScript which comes with and is an integral part of the Macintosh operating system.
The Story Behind the Story
Here's how it works: To accomplish the tasks you require or request, the operating system and the applications on your computer talk to each other using a special messaging tool called Apple Events.
Apple Events transfer information, commands, and requests between applications, networks, and the Mac OS in much the same way as we use phone calls, pagers or email to communicate with each other. However, unlike the methods we use in our personal lives, Apple Events happen very quickly, behind the scenes, and are invisible to the user.
You can think of Apple Events as applications sending email to each other. Some of these emails are instructions. Some are requests for information. Some contain data and pointers to related files. And some emails contain a bit of everything.
Controlling the Conversation
AppleScript is an English-like language used to intitiate and direct actions within or between applications. AppleScript sentences and statements are saved as scripts. These script files are read by the operating system, which converts the script's instructions into the Apple Event messages it sends to the indicated applications, in order to accomplish the tasks the scripts were designed to address.
Some scripts contain instructions to an application. Some are requests for information. Some send or refer to data for applications to process. Often, scripts perform all of these tasks.
Much more that just a macro-language, AppleScript scripts can "think." Scripts can make decisions based on user-interaction or by parsing and analyzing data, documents or situations. AppleScript scripts can automate much of what we do and save us time and money. Isn't that what computers are supposed to do?
The Chain of Command
Consider the following statements:
Everything in the universe is an object.
Solar systems, planets, continents, cities, buildings, people--even the shoes they wear, all can be described as objects.
Everything belongs to, is related to, is contained in, or is part of something else.
The shoes belong to the person who is in the building in the city on the continent on the planet in the solar system.
This same situation applies to the Mac:
On the Macintosh computer everything is an object.
The computer, the desktop, the disks it displays, the folders on the disks and the files in those folders. All of these items are objects.
Everything belongs to, is related to, is contained in, or is part of something else.
The file is in the folder which is in the disk which is on the desktop which is on the computer.
This relationship between objects is refered to as being "hierarchical" or, in military terms, is the "Chain of Command."
Here's an example of the Chain of Command at work: a general tells the captain who tells the lieutenant who tells the sergeant who tells the private, "Raise the flag!"
Once he's completed his task, the private replys to the sergeant who reports to the leutenant who reports to the captain who reports to the general, "Job done sir!"
You'll use a similar technique often in the scripts you write. Just remember this:
Objects in scripts are described in terms of their position in their hierarchical structure, or where they are in the "Chain of Command".
Beginning AppleScript
Prev Topic: The Chain of Command
Next Topic: "Bob" the Folder
--------------------------------------------------------------------------------
The Script Editor
Our next step in learning to write AppleScript scripts is to... write scripts! To do so, we'll use the Script Editor application.
Every Macintosh comes with the Script Editor application installed. This application is used to read, write, and record AppleScript scripts. It is located in the AppleScript folder within the Apple Extras folder on your startup disk. Open it by double-clicking its icon.
The Script Editor features and use are covered thoroughly in the "Using the Script Editor" section of the AppleScript Help in the Help Center. The following is a brief explanation to get us started, for detailed information read the Script Editor help content.
Once you've opened the Script Editor application, you'll see a window similar to the one below. This is a script window.
If no script window is open, create a new one by typing Command-N or choosing "New Script" from the Script Editor's "File" menu.
Adjust the Script Window
Do the following:
1) Collapse the top field in the script window by clicking the small blue disclosure triangle to the left of the "Description:" text.
2) Drag the Grow Box in the bottom right of the window downward and to the right to expand the script window so we'll have more room for our script text.
3) Position the script window so you can easily switch between this help window and the script window.
Once you've completed these steps, you're ready to write scripts.
Beginning AppleScript
Prev Topic: The Script Editor
Next Topic: Our First Scripts!
--------------------------------------------------------------------------------
"Bob" the Folder
So here we go. In our first script, we'll change a property or attribute of an item in the Finder.
A property is simply a quality that helps define what an item is. An item's size, position, location, label or name are properties of the item. Each of these properties has an assigned value. These values are often expressed in numeric or textual format.
In most cases the value of a property can be read or changed by a script. For example, a script can get or set the name of an item by changing the value of its name property.
For our example scripts, we'll need an object to work with. Let's create a folder and change one of it's properties.
Do the following:
1) Switch to the desktop, and create a new folder by either typing Command-N or selecting "New Folder" from the "File Menu." The Finder will create an untitled folder on the desktop.
2) Change the name of the untitled folder to "Bob".
3) Return to this page by clicking in this window.
"Bob" the folder, will be the target object for our first scripts.
The property of Bob we'll be changing is his label index.
The Label Index Property
Every item displayed by the Finder can be labeled, including: disks, folders and files. To label an item, we normally select the item, go to the File Menu, and pick a label option from the Label popup sub-menu.
Instead, we'll set the value of Bob's label index property by indicating in our script, a corresponding number for the various label options: 0 for None, or 1 thru 7 for the other colored options.
Beginning AppleScript
Prev Topic: Bob the Folder
Next Topic: More Fun with Bob
--------------------------------------------------------------------------------
Our First Script!
Now we're ready to write our first script.
Do the following:
1) Click in the bottom field of the open script window in the Script Editor application, and type the following line:
tell the application "Finder" to tell its item named "Bob" to set its label index to 1
2) Once you've entered the text into the script window, click the "Check Syntax" button on the right of the script window to check your script for errors.
Clicking the "Check Syntax" button causes the Script Editor to examine the script for errors. If none are found, the script is compiled and the words reserved by AppleScript for its use are displayed in boldface type. Script statements are also automatically indented for you.
3) Now, click the "Run" button to execute the script.
4) Locate the folder named Bob on the desktop. Bob is orange!
5) Return to this page by clicking in this window.
Congratulations, you just wrote your first AppleScript script!
Note the following:
The script is following the Chain of Command from the top down. In other words, from the Finder to the item it contains. The script tells the Finder to tell its item to change the value of one of its properties to a specified setting.
The names of objects are placed within straight quotes (" "). When writing scripts, proper names and text information are always encased in this manner.
Script Number Two!
Now let's try the same actions but using a script which addresses the Chain of Command from the bottom up or from the target item to its container or owner.
Do the following:
1) Click anywhere in the bottom field in the script window.
2) Clear the existing script from the script window by typing Command-A or choosing "Select All" from the "Edit Menu," and then hitting the Delete Key.
3) Enter the following line in the bottom field of the script window:
tell the item named "Bob" of the application "Finder" to set its label index to 2
4) Click the "Check Syntax" button on the right of the script window to make sure you've entered the script exactly as shown above.
5) Click the "Run" button to execute the script.
6) Switch to the desktop and guess what? Bob is red, which is the color of the second label option.
7) Return to this page by clicking anywhere in this window.
Summary
Note the following:
We've seen from these examples that scripts can be used to change the values of the properties of items.
Script commands point to target items by describing the item's position in the Chain of Command from the top down or from the bottom up.
Beginning AppleScript
Prev Topic: Our First Scripts!
Next Topic: Bob's on the Move!
--------------------------------------------------------------------------------
More Fun with Bob
We've seen we can change the value of the label index property of our folder. Now, let's try changing Bob's position on the desktop.
The Position Property
Every item displayed in icon form on the desktop or within a folder window has a position within that window.
The value of an item's position property is expressed as a list of two numbers: the horizontal distance (in pixels) from the left of the desktop or window, and the vertical distance (in pixels) from the top of the desktop or window.
For example, the position of an item 72 pixels from the left of the desktop or window and 47 pixels from the top of the desktop or window would be expressed as: {72, 47}
Note the following concerning lists:
Lists in AppleScript are always comma delimited. In other words, the elements of a list are separated by commas.
A list begins with the opening brace character "{" and ends with the closing brace character "}".
Lists can contain numeric or text elements or combinations of both. For example, here's a list of four numbers: {6, 40, 640, 480}.
Here's a list of three names: {"Bob","Sue","Sal"}.
Here's a list of names and numbers: {"Zola", 23, 345, "Ted", "Bob"}.
The following images illustrate the position of an item within the desktop or folder window:
Let's Move Bob!
Let's write a script which will place Bob the folder at a specified location on the desktop.
Do the following:
1) Clear the existing script from the script window in the Script Editor application.
2) Type the following script:
tell application "Finder" to set the position of the item named "Bob" to {72, 47}
3) Check the script syntax and run the script
4) Locate Bob on the desktop. You'll find him at the top left of the desktop, exactly 72 pixels from the left of the screen and 47 pixels from the top of the screen.
6) Click in this window to return to this page.
Beginning AppleScript
Prev Topic: More Fun With Bob
Next Topic: The Tell Block
--------------------------------------------------------------------------------
Bob on the Move
Let's try some more scripts using Bob. But first, we'll write a script which will move Bob to a new location.
Do the following:
1) Clear the existing script from the script window by typing Command-A or choosing "Select All" from the "Edit Menu," and then hitting the Delete Key.
2) Enter the following line in the bottom field of the script window:
tell application "Finder" to move the item named "Bob" to the startup disk
3) Check the script syntax and run the script.
Bob the folder has now been moved to the startup disk!
Next, we'll write a script which changes the contents of the comments field of Bob's information window.
The Comment Property
Every item on the computer, whether a file, folder, or disk has an information window which can be accessed by selecting the item and choosing the General Information sub-menu of the Get Info menu item of the File menu.
Doing so will summon the Information Window for the selected item. As shown in the following illustration, the General Information panel of the Information contains a Comments field.
Setting the Comment Property
Let's create a script which will alter the contents of Bob's Comments field.
Do the following:
1) Delete any existing script in the script window and write the following script. Be sure to replace "Macintosh HD" with the name of your startup disk if it is different. Since Bob is in a new location, the Chain of Command will reflect his new status as being contained in the startup disk.
tell application "Finder" to tell the item named "Macintosh HD" to �
tell its item named "Bob" to set its comment to "Hello, my name is Bob!"
Note that the "�" character is generated by typing Option-L on the keyboard.
If a script is too long to fit on a single line, it can be adapted to fit on two lines by adding the "next line" character (�) at the line break. This character used by AppleScript as a way of having long lines displayed in shorter segments.
2) Check the script's syntax and run the script.
If you access the information for Bob the folder, you'll see the indicated comments have been added to the Comments field in Bob's information window.
Notice the following concerning the preceeding script:
1) Bob is now an item belonging to the startup disk which in turn belongs to the Finder application.
2) The Chain of Command order is from the top down or from the Finder to the item.
Now let's try the same script written following the Chain of Command from the bottom up.
Do the following:
1) Clear the script window and write the following:
tell the item named "Bob" of the item named "Macintosh HD" of �
application "Finder" to set its comment to �
"My proper name is Robert, but you can call me Bob!
2) Run the script and the contents of Bob's Comments field changes to reflect the new text.
Optional Words
As you can see, script statements can become very long. You can shorten them a bit by removing the words "named" and "the". These words are optional and you can leave them out of your scripts if you choose to do so. Scripts will execute the same without them. For example, enter and run the following script:
tell item "Bob" of item "Macintosh HD" of application "Finder" to �
set its comment to "I sure do love all this attention!"
Beginning AppleScript
Prev Topic: More Fun With Bob
Next Topic: Nested Tell Blocks
--------------------------------------------------------------------------------
The Tell Block
Let's examine the following script. It is composed of a series of three statements or commands which change the values of various properties of our friend, Bob the folder.
tell application "Finder" to tell item "Macintosh HD" to tell item "Bob" to �
set its label index to 4
tell application "Finder" to tell item "Macintosh HD" to tell item "Bob" to �
set its position to {72, 120}
tell application "Finder" to tell item "Macintosh HD" to tell item "Bob" to �
set its comment to "Yes, I'm still here!"
As you can see, scripts written using only simple single-line tell statements can be very long, cumbersome, wordy and make it difficult to direct a series of actions at a specific target object without doing a lot of writing!
There is a way to shorten the length of statements, allow for multiple actions, and present scripts in an organized visual manner. It is refered to as the tell block.
Here's how it works:
You begin a tell block with a tell statement targeting a specific item or application. In this case the target item is our friend Bob the folder.
tell application "Finder" to tell item "Macintosh HD" to tell item "Bob"
Next follows each command or request statement for the target object.
set its label index to 4
set its position to {72, 120}
set its comment to "Yes, I'm still here!"
After the commands or statements, you close the tell block with the phrase: end tell.
end tell
Here's the original script and the script using a tell block:
tell application "Finder" to tell item "Macintosh HD" to tell item "Bob" to �
set its label index to 4
tell application "Finder" to tell item "Macintosh HD" to tell item "Bob" to �
set its position to {72, 120}
tell application "Finder" to tell item "Macintosh HD" to tell item "Bob" to �
set its comment to "Yes, I'm still here!"
tell application "Finder" to tell item "Macintosh HD" to tell item "Bob"
set its label index to 4
set its position to {72, 120}
set its comment to "Yes, I'm still here!"
end tell
The second script will function exactly as the first one only it is more concise, easier to understand, and easier to write.
Any statements between the tell block opening and closing are read by the script as being directed at the target object refered to in the tell block opening, in this case: Bob the folder.
tell application "Finder" to tell item "Macintosh HD" to tell item "Bob"
-- the following commands are directed at Bob the folder
set its label index to 4
set its position to {72, 120}
set its comment to "Yes, I'm still here!"
end tell
Since any actions within the tell (target object) and the end tell lines are interpreted by the script as being directed at the target object, the word "its" becomes optional and can be left out. The following script functions just the same as the one above.
tell application "Finder" to tell item "Macintosh HD" to tell item "Bob"
set label index to 4
set position to {72, 120}
set comment to "Yes, I'm still here!"
end tell
Beginning AppleScript
Prev Topic: The Tell Block
Next Topic: Summary
--------------------------------------------------------------------------------
Nested Tell Blocks
In the previous section we were introduced to the tell block as a way of focusing and condensing commands.
The following script composed of multiple single-line tell statements:
tell application "Finder" to tell item "Macintosh HD" to tell item "Bob" to �
set its label index to 4
tell application "Finder" to tell item "Macintosh HD" to tell item "Bob" to �
set its position to {72, 120}
tell application "Finder" to tell item "Macintosh HD" to tell item "Bob" to �
set its comment to "Yes, I'm still here!"
Was changed to:
tell application "Finder" to tell item "Macintosh HD" to tell item "Bob"
set the label index to 4
set the position to {72, 120}
set the comment to "Yes, I'm still here!"
end tell
We can further condense the script by creating a tell block for each of the items targeted in the previous script's opening statement.
The new tell blocks will nest inside each other and will automatically be indented, when the script syntax is checked, to reflect their target object's position in the chain of command:
tell application "Finder" to tell item "Macintosh HD" to tell item "Bob"
set the label index to 4
set the position to {72, 120}
set the comment to "Yes, I'm still here!"
end tell
Becomes:
tell application "Finder"
tell item "Macintosh HD"
tell item "Bob"
set the label index to 4
set the position to {72, 120}
set the comment to "Yes, I'm still here!"
end tell
end tell
end tell
The tell block for disk Macintosh HD is within the Finder tell block since the disk is part of the Finder's chain of command. The tell block for folder Bob is within the disk Macintosh HD tell block since the folder is part of the disk's chain of command. In other words, the chain of command is now represented by indented tell blocks.
Adding Terms
Since the script is now within the scope of the Finder tell block, we can use terms in our script which are understood and used by the Finder. For example, tell item "Macintosh HD" can now become tell disk "Macintosh HD" and tell item "Bob" can now become tell folder "Bob". The terms disk and folder are recognized and used by the Finder to identify specific types of items.
tell application "Finder"
tell disk "Macintosh HD"
tell folder "Bob"
set the label index to 4
set the position to {72, 120}
set the comment to "Yes, I'm still here!"
end tell
end tell
end tell
Multiple Scripting Targets
Let's try using the tell block technique to create a script which will change the property values of a group of items.
Do the following:
1) Switch to the desktop and make two new folders on the startup disk. Name the new folders: Sam and Sue. Set the view of the disk's window to display icons.
2) Enter the following script into a new script window:
tell application "Finder"
tell disk "Macintosh HD"
tell folder "Bob"
set the label index to 1
set the position to {36, 36}
set the comment to "Hey, I'm Bob!"
end tell
tell folder "Sue"
set the label index to 2
set the position to {36, 90}
set the comment to "Hey, I'm Sue!"
end tell
tell folder "Sam"
set the label index to 3
set the position to {36, 144}
set the comment to "Hey, I'm Sam!"
end tell
end tell
end tell
3) Run the script. Notice how the folders' appearance and position changed.
Notice in the preceding script how the tell block for the individual folders are placed within the tell block for the disk since the folder reside on or are contained in the disk.
AppleScript Syntax
In our day-to-day conversations we use don't always say the same thing in the same way. Instead, we use a variety of phrase constructions to create our sentences. AppleScript too, can understand a variety of command or statement structures.
For example, both the following commands will accomplish the same task:
tell application "Finder" to set the position of item named "Bob" to {72, 47}
tell application "Finder" to tell item "Bob" to set its position to {72, 47}
While the result of both scripts is to position Bob the folder on the desktop, the first script directs the Finder to change Bob's position while the second script directs Bob to change his position. Both methods are understood by AppleScript.
In both commands:
1) The position property is clearly stated as being an attribute of the target object. In other words, "position of" or "its position" clearly define position as a property belonging to Bob the folder.
2) The object's position in the Chain of Command is clearly defined. Bob the folder belongs to the Finder application.
As a matter of fact, we could even use the following command:
tell the application "Finder" to set item "Bob"'s position to {72, 47}
If the variety of AppleScript syntax options are daunting to absorb, here's a simple syntax that you can use in your scripts:
Tell the owner to set the property of the target object to a specified value. As in:
tell the application "Finder" to set the position of folder "Bob" to {72, 47}
or in a tell block:
tell application "Finder"
set the position of folder "Bob" to {72, 47}
end tell
Beginning AppleScript
Prev Topic: Nested Tell Blocks
Next Topic: Introduction
--------------------------------------------------------------------------------
Summary
Congratulations! You've completed your first look at AppleScript and are nearly ready to move to the next tutorial concerning basic Finder scripting.
Before you do, let's re-examine the main lessons of this overview:
Everything in the Mac OS is an object which belongs to or is contained in other objects.
For example, applications, files, folders, disks, alias files, control panels, and font suitcases are all examples of scriptable objects.
Objects are described in scripts in terms of their position in their hierarchical structure, or where they are in the "Chain of Command".
For example, a file is contained in a folder which is on the disk which is displayed in the Finder application.
item "Bob" of item "Macintosh HD" of application "Finder"
All scriptable objects have qualities or properties whose values can be controlled using script AppleScript scripts.
In this first look at AppleScript we examined three properties of Finder items: label index, position, and comment.
Script commands or requests are targeted at objects using the tell statement. Multiple commands can be targeted at objects by combining the commands in tell blocks.
An example of a single tell statement:
tell application "Finder" to set the label index of folder "Bob" to 3
An example of multiple commands combined in a tell block:
tell application "Finder"
tell folder "Bob"
set the label index to 3
set the position to {48, 48}
set the comment to "I can write scripts!"
end tell
end tell
The Next Step
The Finder Scripting Basics Tutorial is the next step for you in learning to write AppleScript scripts. This tutorial covers basic script writing techniques, properties of items, and the set, get, make, move, duplicate, and delete commands.
The Finder Scripting Basics Tutorial is located in the Mac OS 8.5 Help System. It can be accessed by choosing Help Center from the Finder's Help menu and then choosing AppleScript Help in the forthcoming page.
Beginning AppleScript
Prev Topic: The Tell Block
Next Topic: Summary
--------------------------------------------------------------------------------
Nested Tell Blocks
In the previous section we were introduced to the tell block as a way of focusing and condensing commands.
The following script composed of multiple single-line tell statements:
tell application "Finder" to tell item "Macintosh HD" to tell item "Bob" to �
set its label index to 4
tell application "Finder" to tell item "Macintosh HD" to tell item "Bob" to �
set its position to {72, 120}
tell application "Finder" to tell item "Macintosh HD" to tell item "Bob" to �
set its comment to "Yes, I'm still here!"
Was changed to:
tell application "Finder" to tell item "Macintosh HD" to tell item "Bob"
set the label index to 4
set the position to {72, 120}
set the comment to "Yes, I'm still here!"
end tell
We can further condense the script by creating a tell block for each of the items targeted in the previous script's opening statement.
The new tell blocks will nest inside each other and will automatically be indented, when the script syntax is checked, to reflect their target object's position in the chain of command:
tell application "Finder" to tell item "Macintosh HD" to tell item "Bob"
set the label index to 4
set the position to {72, 120}
set the comment to "Yes, I'm still here!"
end tell
Becomes:
tell application "Finder"
tell item "Macintosh HD"
tell item "Bob"
set the label index to 4
set the position to {72, 120}
set the comment to "Yes, I'm still here!"
end tell
end tell
end tell
The tell block for disk Macintosh HD is within the Finder tell block since the disk is part of the Finder's chain of command. The tell block for folder Bob is within the disk Macintosh HD tell block since the folder is part of the disk's chain of command. In other words, the chain of command is now represented by indented tell blocks.
Adding Terms
Since the script is now within the scope of the Finder tell block, we can use terms in our script which are understood and used by the Finder. For example, tell item "Macintosh HD" can now become tell disk "Macintosh HD" and tell item "Bob" can now become tell folder "Bob". The terms disk and folder are recognized and used by the Finder to identify specific types of items.
tell application "Finder"
tell disk "Macintosh HD"
tell folder "Bob"
set the label index to 4
set the position to {72, 120}
set the comment to "Yes, I'm still here!"
end tell
end tell
end tell
Multiple Scripting Targets
Let's try using the tell block technique to create a script which will change the property values of a group of items.
Do the following:
1) Switch to the desktop and make two new folders on the startup disk. Name the new folders: Sam and Sue. Set the view of the disk's window to display icons.
2) Enter the following script into a new script window:
tell application "Finder"
tell disk "Macintosh HD"
tell folder "Bob"
set the label index to 1
set the position to {36, 36}
set the comment to "Hey, I'm Bob!"
end tell
tell folder "Sue"
set the label index to 2
set the position to {36, 90}
set the comment to "Hey, I'm Sue!"
end tell
tell folder "Sam"
set the label index to 3
set the position to {36, 144}
set the comment to "Hey, I'm Sam!"
end tell
end tell
end tell
3) Run the script. Notice how the folders' appearance and position changed.
Notice in the preceding script how the tell block for the individual folders are placed within the tell block for the disk since the folder reside on or are contained in the disk.
AppleScript Syntax
In our day-to-day conversations we use don't always say the same thing in the same way. Instead, we use a variety of phrase constructions to create our sentences. AppleScript too, can understand a variety of command or statement structures.
For example, both the following commands will accomplish the same task:
tell application "Finder" to set the position of item named "Bob" to {72, 47}
tell application "Finder" to tell item "Bob" to set its position to {72, 47}
While the result of both scripts is to position Bob the folder on the desktop, the first script directs the Finder to change Bob's position while the second script directs Bob to change his position. Both methods are understood by AppleScript.
In both commands:
1) The position property is clearly stated as being an attribute of the target object. In other words, "position of" or "its position" clearly define position as a property belonging to Bob the folder.
2) The object's position in the Chain of Command is clearly defined. Bob the folder belongs to the Finder application.
As a matter of fact, we could even use the following command:
tell the application "Finder" to set item "Bob"'s position to {72, 47}
If the variety of AppleScript syntax options are daunting to absorb, here's a simple syntax that you can use in your scripts:
Tell the owner to set the property of the target object to a specified value. As in:
tell the application "Finder" to set the position of folder "Bob" to {72, 47}
or in a tell block:
tell application "Finder"
set the position of folder "Bob" to {72, 47}
Beginning AppleScript
Prev Topic: Nested Tell Blocks
Next Topic: Introduction
--------------------------------------------------------------------------------
Summary
Congratulations! You've completed your first look at AppleScript and are nearly ready to move to the next tutorial concerning basic Finder scripting.
Before you do, let's re-examine the main lessons of this overview:
Everything in the Mac OS is an object which belongs to or is contained in other objects.
For example, applications, files, folders, disks, alias files, control panels, and font suitcases are all examples of scriptable objects.
Objects are described in scripts in terms of their position in their hierarchical structure, or where they are in the "Chain of Command".
For example, a file is contained in a folder which is on the disk which is displayed in the Finder application.
item "Bob" of item "Macintosh HD" of application "Finder"
All scriptable objects have qualities or properties whose values can be controlled using script AppleScript scripts.
In this first look at AppleScript we examined three properties of Finder items: label index, position, and comment.
Script commands or requests are targeted at objects using the tell statement. Multiple commands can be targeted at objects by combining the commands in tell blocks.
An example of a single tell statement:
tell application "Finder" to set the label index of folder "Bob" to 3
An example of multiple commands combined in a tell block:
tell application "Finder"
tell folder "Bob"
set the label index to 3
set the position to {48, 48}
set the comment to "I can write scripts!"
end tell
end tell
The Next Step
The Finder Scripting Basics Tutorial is the next step for you in learning to write AppleScript scripts. This tutorial covers basic script writing techniques, properties of items, and the set, get, make, move, duplicate, and delete commands.
The Finder Scripting Basics Tutorial is located in the Mac OS 8.5 Help System. It can be accessed by choosing Help Center from the Finder's Help menu and then choosing AppleScript Help in the forthcoming page.