Name

Finder Classes

Dictionary classes

application

This class represents the Finder itself. See Figure 15-1 for a visual depiction of the Finder application object and its elements and properties. You can grab a list of references to any of the elements by using the plural version of the element as a command:

tell app "Finder" to application processes

This code returns a list of all the programs that are running on the computer at the moment.

The following are application elements:

selection reference

Anything that happens to be selected at the time (such as a file or folder on the desktop) is returned as a reference by the selection property. Code such as:

tell app "Finder" to get selection

provides a “list of references” return type such as {file "Internet Explorer" of application "Finder"}.

sharing starting up boolean (read-only)

If file sharing is in the process of starting up then this property returns true.

application file

An application file is a child class of file that adds a few more properties. In other words, it inherits some file properties such as file type and creator type. This is a file that you double-click to open a software program.

The following are application file properties:

container

A container is a folder or a disk (an item that contains other items). container is a subclass of item, so it inherits all of item’s properties. It also has its own properties, which are specified in the following list. container is the super class of folder and disk. You can get all the desktop containers with code such as:

tell app "Finder" to get containers

All of the elements described here can be contained by a container (i.e., a container can contain accessory suitcases and alias files). The following container elements are described in their corresponding class description in this chapter:

accessory suitcase
alias file
application file
clipping
container
desk accessory file
document file
file
folder
font file
font suitcase
internet location
item
package
sharable container
sound file
suitcase

The following are container properties:

container window

This is a kind of Finder window that contains items, such as a folder that is double-clicked to produce a window. It has all of the window class’s properties, depending on whether the container window is set as a pop-up window or a standard Finder window in Finder’s View menu. It also has some of its own special properties, which can be obtained with syntax such as:

calculates folder sizes of container window "today"

The following are container window properties:

The following is a desk accessory elements:

trash trash-object

This is the class for that trusty drum that sits on your desktop. It is a container for items that are deleted when you “empty” the trash (by sending the Finder an empty command). You can get the contents of the trash by querying the items of trash. The trash object class only has one distinct property called warns before emptying. This is the equivalent of checking the “Warn before emptying” checkbox in the trash’s Information Window (select the trash icon and type Command-I).

disk

A disk is a specialized container or sharable container, and thus inherits the properties of these parent classes along with embodying a few attributes of its own. Important properties for managing disks in AppleScript are capacity and free space. The following code finds all the alias files on a disk, including those buried in any nested folders:

tell application "Finder"
   alias files of (entire contents of disk "HFSA2gig")
end tell

The descriptions of the following disk elements are the same as their class descriptions:

accessory suitcase
alias file
application file
clipping
container
desk accessory file
document file
file
folder
font file
font suitcase
internet location
item
package
sharable container
sound file
suitcase

The following are disk properties:

document file

A document file is a subtype of the file class that has a different file type than other kinds of files. A document file might have a file type of 'TEXT' while an application file has a file type of 'APPL'. If you want to just get references to the text and word-processing files on the desktop, for example, use code such as:

tell app "Finder" to get document files

The document file class inherits all of the file class’s properties.

file

file is the super class for the other file subtypes, such as document file, alias file, and application file. It is also a subclass of item so it has an item’s properties. There are generally two ways to refer to files. The Finder’s terminology is the inside-out method of file referral, as in:

file "chap15" of folder "today" of desktop

You can also use the keyword file followed by the full path to the file, as in:

file "macintosh hd:desktop folder:today:chap15"

One easy way to get a file reference is to hit the record button on Script Editor then select the file in the Finder. Or, select the file and paste the reference inside of a Finder tell statement by using Script Editor’s Edit:Paste Reference menu item.

The following are file properties:

folder

This is a class for a typical Finder folder. It is also a subclass of sharable container and, further up the inheritance tree, container and item. Therefore, it also shares the relevant properties of those classes. You can get all of the folders in a directory tree with the following simple AppleScript command in Mac OS 9:

tell app "Finder" to get folders of (entire contents of folder¬ "bigDeepFolder")

All of the following folder elements, the things that you can place and store in a folder, are the same as their class descriptions in this chapter. Refer to them in the manner of document files of folder "today". Or, more generally, items of folder "today". The following are folder elements:

accessory suitcase
alias file
application file
clipping
container
desk accessory file
document file
file
folder
font file
font suitcase
internet location
item
package
sharable container
sound file
suitcase
font file

A font file is a special subclass of file that usually lives in the startup disk:System Folder:Fonts folder. It has all of the relevant properties of a file and, by extension, an item.

font suitcase

This is a special kind of suitcase or container that can only contain font files. Figure 15-5 shows a font suitcase. A font suitcase inherits from suitcase and file; it has a file type of 'FFIL' The following are font suitcase elements.

item

You can get a list of a font suitcase’s contents with syntax such as:

items of suitcase "Adobe Sans MM" of fonts folder.
icon family

This class is the return value for the icon property of an item. Items like files and applications on the desktop have icons that visually identify them. You can get the data for these images by querying their icon properties. The following example stores in a variable the icon property of a desktop file, then gets the icon’s small eight bit icon property. The return value for the small eight bit icon property is of type raw data (see Chapter 3 for the raw-data description). The following code shows an example raw-data value for this icon family member. The raw data value mostly consists of a long series of hexadecimal numbers (e.g., AFFF). The return value in the dictionary entry for icon family (e.g., “ics8”) is a four-character code that represents a particular icon type. A sample abbreviated version of this return value is <<data ics8000000...>>. Broken down into its components, this is the left double-arrow or guillemet character (“<<”), followed by the word “data” and a space, then the four-character identifier for the icon (e.g., “ics8”), a long series of hexadecimal numbers, and finally the closing guillemet (“>>”).

tell application "Finder"
   set ic to icon of file "auto_insure_info"
   small eight bit icon of ic
end tell
(* sample return value for 'small eight bit icon' *)
<<data ics8000000FFFFFFFFFFFFFFFFFFFF000000000000FFF5F5F5F5F5F5F5F5FFFF
0000000000FFF5FFF5F5F5F5F5F5FF2BFF00000000FFFF2AFFF5F5FDFDF5FFFFFFFF00000
0FF2A2A2AFFF5F5F5F5F5F5F5FF0000FF2AFF2A2A2AFFF5F5FDFDF5F5FF00FF2A2AFF2A2A
2A2AFFF5F5F5F5F5FFFF2A2A2AFFFFFF2A2A2AFFF5FDFDF5FFFF2A2A2AFF2A2AFF2A2AFFF
5F5F5F5FF00FF2A2AFF2A2AFF2AFFF5F5FDFDF5FF0000FF2AFFFFFF2AFFF5F5F5F5F5F5FF
000000FF2A2A2AFFF5F5FDFDFDF5F5FF000000FFFF2AFFF5F5F5F5F5F5F5F5FF000000FFF
5FFF5F5FDFDFDFDFDFDF5FF000000FFF5F5F5F5F5F5F5F5F5F5F5FF000000FFFFFFFFFFFF
FFFFFFFFFFFFFF>>

large 32 bit icon ‘il32’

The large 32-bit color icon for the file

large 4 bit icon ‘icl4’

The large 4-bit color icon

large 8 bit icon ‘icl8’

The large 8-bit color icon

large 8 bit mask ‘l8mk’

The large 8-bit mask for large 32-bit icons

large monochrome icon and mask ‘ICN#'

The large black-and-white icon and the mask for large icons

small 32 bit icon ‘is32’

The small 32-bit color icon

small 4 bit icon ‘ics4’

The small 4-bit color icon

small 8 bit icon ‘ics8’

The small 8-bit color icon

small 8 bit mask ‘s8mk’

The small 8-bit mask for small 32-bit icons

small monochrome icon and mask ‘ics#':

The small black-and-white icon and the mask for small icons

information window

This is the window subclass for the Get Info window. This window is displayed when you select a file and type Command-I or choose Get Info from the Finder’s File menu. Its properties are derived from the information that is displayed in this window. You get an information-window object by querying an item’s information window property, as in information window of item “today” (if item “today” was a folder called “today”). The following are information window properties:

comment international text

This is the text from the comment area of the Get Info window. This is a settable property, as in:

set comment of (information window of item "today") to "A¬
folder for today"
creation date date (read-only)

This is the date when the item associated with this window was created.

current panel constant

This property can be any one of the following constants, depending on which part of the information window is showing: General Information panel, Sharing panel, Memory panel, Status and Configuration panel, Fonts panel.

icon icon family

This is the icon family of the icon property for the item associated with this window.

item reference (read-only)

This is the item associated with this information window. See the item class description.

locked boolean

If the file associated with this information window is locked then this property is true.

minimum size integer

This property is derived from the Memory section of the Get Info window (select an application and type Command-I). Its return value represents the minimum memory size in bytes that can be used to run the program.

modification date date

The date when the item associated with this window was last modified. You can arbitrarily change the modification date of an item as displayed in its information window with code such as the following, which alters the modification date of the item to the day before the current day. See the date object description in Chapter 3.

tell application "Finder"
   set modification date of (information window of (item¬  
   "today")) to ((current date) - (1 * days))
end tell
physical size integer (read-only)

This is the physical size in bytes of the information window’s item, which is the total amount of space the item takes up on disk. See the size property description for the information window object.

preferred size integer

The integer that corresponds to the Preferred Size: field in the information window. This property is derived from the Memory section of the Get Info window (select an application and type Command-I). Its return value represents the preferred memory size in bytes that can be used to run the program. If there is enough memory when the software program is executed, then this is the amount of RAM in Mac OS 9 reserved for the application.

product version international text (read-only)

This property represents the product version identified at the top of the Get Info window.

size integer (read-only)

This is the logical size in bytes of the item associated with the information window. This size is the actual number of bytes represented by the file and is usually smaller than the physical size number, which represents the total space taken up on the hard disk by the item. The following example shows the Script Editor’s Event Log for querying these properties:

tell application "Finder"
   get size of information window of item "today"
   --> 3.85481E+5
   get physical size of information window of item "today"
   --> 4.39296E+5
end tell
stationery boolean

This property is true if the item associated with the information window is a stationery pad or file template.

suggested size integer (read-only)

The application’s author suggested at least this much memory for standard performance, in bytes. This property is derived from the Memory section of the Get Info window (select an application and type Command-I). Suggested size is provided by the application file’s programmer; you cannot change it. Its return value represents the suggested memory size in bytes that should be used to run the program.

version international text (read-only)

This property represents the version of the file that is displayed at the bottom of the Get Info window.

warns before emptying boolean

This true/false value is only applicable to the trash’s Get Info window. If true, a dialog window is displayed before items are deleted from the trash.

internet location file

This class represents a file that, when double-clicked, opens up your default browser and loads the web page identified in its location property. Figure 15-6 shows an internet location file.

The following is an internet location file property:

item

item is the super class for the non-Window Finder objects. Disks, files, folders, and other objects that can be manipulated in the Finder are all items, and therefore have the following item properties. To get the names of all the objects in a folder, you can use syntax such as:

name of (items of folder "today")

The following are item properties:

bounds bounding rectangle

The bounds returns all four coordinates for the icon of an item in its container. This is a settable property, as in:

set bounds of item "today" to {22, 62, 38, 78}
comment international text

This property is the comment section from the item’s Get Info window. It can be an empty string if the user has not provided a comment for the item.

container reference

This is a reference to the container, such as a folder, of the item. You can find out which object contains an item with syntax such as:

get container of item
"myfile"
content space reference

This property returns the window that would open if the item were opened.

creation date date (read-only)

This property represents the date on which the item was created. The return value is a date object so you can get date-related properties of creation date, as in time string of theDate. See the date description in Chapter 3.

description international text

The description property is a long string about the item along the lines of:

"BBEdit 5.1 document" & return & "You can open and
modify this document using the BBEdit 5.1 application
program."
disk reference

This property represents the disk that is currently storing an item. If you reference the disk of desktop item, the return value might look like:

startup disk of application "Finder" 
To get more information about this disk, you can use code such as name of (disk
of file "auto_insure" of folder "today")
folder reference

This property represents the folder in which the item resides. It returns a reference to that folder as in:

folder "today" of application
"Finder"
icon icon family

This property represents the icon associated with the item. See the icon family class description.

index integer

This property represents the item’s 1-based numerical position in its container. Using the index is a good way to iterate over the elements of a container using a repeat loop.

information window reference

This property returns an information window object representing this item’s Get Info window. The Finder displays these windows when you select the item and type Command-I or choose Get Info from the Finder’s File menu. See the information window class description.

id integer

Items on the desktop have unique id numbers. The id numbers don’t change, even if the item is renamed and moved into a new folder. Therefore, you can use the id to track an item accurately, as in item whose id is 386397. For instance, the code ids of files returns a list that looks like {387321, 386397, 374477, 378392, 386776}.

kind international text

This string is the “kind” value (found under the kind column in a folder list view) of the item. This is a descriptive phrase about the item like “BBEdit text file.”

label index integer

This property returns a number associated with a particular colored label. You can assign these labels in the label section of the item’s information window. The number reflects the position of the label in the label pop-up menu button. For example, the label “Hot” could be associated with the number 2.

modification date date

This property represents the date on which the item was last modified. The return value is a date object so you can get date-related properties of modification date, as in time string of theDate. This property is settable, unlike creation date. See the date description inChapter 3.

name international text

This is the item’s name in the Finder, as in “today” for a folder called “today.”

physical size integer (read-only)

This integer represents the total number of bytes an item is taking up on its disk.

position

position returns the pixel coordinates of the upper left corner of the item in its container. The return value looks like {82,75}; in other words, a list of integers. If the container is not in button or icon view (i.e., it’s in list view in the Finder’s View menu) then this property returns {-1,-1}.

selected boolean

If the item is selected in its container, such as selecting a file or folder on the desktop, then this property is true.

size integer (read-only)

This is the logical size in bytes of an item on the hard disk, as in a 2,048 byte file in a 16,384 segment of the disk. In this case, size would return 2048.

window reference

Window returns the window object for the window that would open if the item were opened. See the window class description in this chapter.

label

A label object is associated with the various label colors that you can assign to files and folders. You cannot make a new label with the Finder’s make command, however. label is not a property of an item or other object (item does have a label index property), so it is difficult to find a use for this object. The following are label properties:

color RGB color

This returns the label color as an RGB color, which is a list of integers like {204,255,204}. See the RGB Color class description inChapter 3.

index integer

This is the number of the label in the label pop-up menu (which is displayed on Get Info windows).

name international text

This is the name of the label as a string.

package

A package is a specialized item, like a folder, which contains an application file and its support files such as libraries and help files. A package must have an alias file at its top level. This alias file points to the application file in the package. The following web site describes packages: http://developer.apple.com/technotes/tn/tn1188.html. The purpose of packages is for software developers to include an application and all of its dependent files in a neat “package,” as opposed to depositing more files into the Preferences folder and other System Folder directories.

preferences

This class represents the object that is returned by the Finder application class’s Finder preferences property. As you might have guessed, these properties allow the getting and setting of various Finder attributes. These preferences are also available from the Finder’s Edit:Preferences... menu. For example, if you set the preferences property uses wide grid to true (it’s a boolean value), then this action has the same effect as going to Edit:Preferences... and choosing the Wide radio button under Grid Spacing in the General Tab. This is illustrated in Figure 15-7.

The following are preference properties:

button view arrangement constant

This property returns one of the following constants, which determine how buttons are arranged in containers that have a button view: not arranged, snap to grid, arranged by name, arranged by modification date, arranged by creation date, arranged by size/arranged by kind, arranged by label.

button view icon size integer

This property returns or sets the icon size of buttons in a Finder button view (i.e., the contents in a folder are displayed as buttons). The same preference can be set from the View tab in the Finder Preferences window.

calculates folder sizes boolean

This true/false value determines whether folder sizes are displayed in list-view windows (select a folder and choose View:as List from the Finder menu). This is a settable property, as in set calculates folder sizes to true.

delay before springing integer

You can use this property to set the ticks (60 per second) before a container like a folder springs open. The shortest delay is 12; 60 is the longest. Setting this property is the equivalent of setting the “Delay before opening” control in the Finder Preferences General tab.

list view icon size integer

This settable property represents the size of icons in Finder list views (for example, files are listed in the folders rather than appearing as buttons).

shows comments boolean

If shows comments is true, then any comments associated with a file are displayed in Finder list views. This property can also be set in the appropriate checkbox in the Views tab of the Finder Preferences window.

shows creation date boolean

If shows creation date is true, then the creation date of files are displayed in Finder list views. This property can also be set in the appropriate checkbox in the Views tab of the Finder Preferences window.

shows kind boolean

If shows kind is true, then the kind of a file is displayed in Finder list views. An example of a kind property is “application program.” This property can also be set in the appropriate checkbox in the Views tab of the Finder Preferences window.

shows label boolean

If shows label is true, then any labels associated with a file are displayed in Finder list views. This property can also be set in the appropriate checkbox in the Views tab of the Finder Preferences window.

shows modification date boolean

If shows modification date is true, then a file’s modification date is displayed in Finder list views. This property can also be set in the appropriate checkbox in the Views tab of the Finder Preferences window.

shows size boolean

If shows size is true, then the space that the file is taking up on the hard disk is displayed in Finder list views. This property can also be set in the appropriate checkbox in the Views tab of the Finder Preferences window.

shows version boolean

If shows version is true, then any file versions are displayed in Finder list views. This property can also be set in the appropriate checkbox in the Views tab of the Finder Preferences window. Most ordinary text files do not have a version so this file property returns the string “n/a”.

spatial view arrangement constant

This property can be one of the following constants: not arranged, snap to grid, arranged by name, arranged by modification date, arranged by creation date, arranged by size, arranged by kind, arranged by label. If the files in a folder are in “icon view,” for instance, then these constants determine how the icons are sorted (e.g., arranged by name).

spatial view icon size integer

This number is designed to determine the size of the icons when the files are in icon view, for instance. However, setting the icon size to various integer values does not appear to effect how icons are displayed under Mac OS 9.

spring open folders boolean

This true/false property determines whether folders automatically open (“spring open”) when the cursor is positioned on them (and they are closed) for a specified short delay. You can use code such as:

set spring open folders to
false
uses relative dates boolean

This true/false property can also be set from the Views tab of the Finder Preferences window. It determines whether a list-view folder shows a recent date as “Today” or “Yesterday” or in standard date format (e.g., “Fri, Jul 07, 2000 6:15 PM”).

uses simple menus boolean

Setting this property to true is the same as checking “Simple Finder” in the General tab window of the Finder Preferences window.

uses wide grid boolean

Setting this property to false is the same as choose the Tight radio button under Grid Spacing in the Finder Preference’s General tab.

view font integer

This number represents the ID number of the font that the machine is using to display text in the Finder. An example is:

set view font of Finder preferences to
2001
view font size integer

Set the size of the Finder font display using this property, as in:

set view font size of Finder preferences to
12.
window preferences window (read-only):

This property returns the preferences window object associated with the window that is displayed when you choose EditPreferences... from the Finder menu. See the preferences window class description.

preferences window

The preferences window is a window subclass that has one property: current panel. You can thus set the panel in the Finder Preferences to any of those current panel constants, as in:

set current panel of (window of Finder preferences) to¬
Button View Preferences panel.

The following is a preferences window property:

current panel constant

This property can be one of the following constants: General Preferences panel, Label Preferences panel, Icon View Preferences panel, Button View Preferences panel, List View Preferences panel.

process

The process class is the super class for the application process and desk accessory process classes. An application process represents a software program that is running on your computer. For example, the code

tell app "Finder" to get processes

returns a list of process objects, one of which might look like:

process "Adobe® Photoshop® 5.5" of application "Finder"

You can then get various properties for each running process, such as its partition space used. This property gives you the number of bytes of RAM that the process is using (which for Photoshop will probably be quite large!).

The following are process properties:

accepts high level events boolean (read-only)

This property is true if the process object responds to high-level events like Apple events.

accepts remote events boolean (read-only)

This property returns true if the process can accept a remote event (originating from other than the local computer). This example shows the return value of a get accepts remove events command targeting the Finder:

tell application "Finder"
   name of processes
   accepts remote events of processes
end tell
(* return values, first process names *)
{"Control Strip Extension", "DAVE Sharing Extension", "Folder Actions", 
"HP Background", "OSA Menu Lite", "Time Synchronizer", "Web Sharing Extension",
"Outlook Express", "Microsoft Word", "Script Editor", "BBEdit 5.1", "Internet 
Explorer", "Adobe® Photoshop® 5.5", "FileMaker Pro", "Contract Timer"}
(* boolean values reflecting whether each process accepts remote events *)
{false, true, false, true, true, false, false, false, true, true, true, true, 
true, true, true}
creator type (read-only)

This is the creator type for the process, as in “R*ch” for BBEdit, “8BIM” for Photoshop, and “FMP3” for FileMaker Pro. The types of return values actually look like <<class FMP3>>.

file reference (read-only)

This property returns the file object from which the program was launched. If you use the code:

tell app "Finder" to get file of processes

then you will get a large list of file references that look like:

file "FileMaker Pro" of folder "FileMaker Pro 4.1 Folder" of
disk "HFSA2gig"
file type class (read-only)

This property returns the four-character file type of the process, which is often 'APPL' for application. The return value is a class object in raw data form, as in <<class APPL>>.

frontmost boolean

frontmost returns true if the process is the frontmost or active application (i.e., if you select a window on the desktop to make it active, then its associated application is the frontmost one).

has scripting terminology boolean (read-only)

If the application is scriptable (can be controlled by AppleScript), then this value is true.

name international text (read-only)

This property returns the process’s name as text. Get all the names of the processes with the intuitive phrase:

tell app "Finder" to get name of processes
partition space used integer (read-only)

This property returns in bytes the amount of RAM the process is actually using, as opposed to how much RAM has been reserved for the program (see total partition size). The return value of this property may be altered, compared with what it looks like in the About This Computer window (accessed from the upper left corner of the Mac screen), if the machine is using virtual memory.

total partition size integer (read-only)

This number represents the number of bytes of memory with which the program was launched. You can convert this value into megabytes with code such as:

(total partition size of process "FileMaker pro" /1024 /
1024)
visible boolean

If you use code such as the following (in a Finder tell block) then the only processes that the Finder returns are those whose windows and/or menus are visible on the desktop:

get every process whose visible is true

This code phrase doesn’t return any invisible background processes or programs whose windows are no longer displayed (i.e., you Option-clicked the desktop with the program active, making its visible layer vanish).

sharable container

A sharable container is a subclass of container with special file-sharing related properties. A disk or folder that is being shared is considered a subclass of sharable container. The descriptions of the sharable container’s elements are all the same as their class descriptions in this chapter. In terms of a Finder containment hierarchy, a sharable container (like a shared folder) can “contain” other folders. The following are sharable container elements:

accessory suitcase
alias file
application file
clipping
container
desk accessory file
document file
file
folder
font file
font suitcase
internet location
item
package
sharable container
sound file
suitcase

The following are sharable container properties:

exported boolean (read-only)

This is true if the container can be shared (for instance, mounted on another desktop networked via TCP/IP). File sharing must be on to use this property.

group international text

This property gets or sets the file-sharing group or user for the container. For example, if the disk “MYDisk” has a user named “iMac,” then the code phrase group of disk "MYDisk" will return “iMac.”

group privileges sharing privileges

This settable property returns a sharing privileges object for the container. You can also set the group privileges for a sharable container. See the sharing privileges class.

guest privileges sharing privileges

This settable property returns a sharing privileges object for the container. You can also set the guest privileges for a sharable container. See the sharing privileges class.

mounted boolean (read-only)

This property returns true only if file sharing is turned on and the sharable container is mounted on another machine’s desktop.

owner international text

This property returns the owner name as text, but only if file sharing is turned on. Another way to find out a container’s file-sharing owner is by selecting the container, typing Command-I, then choosing the sharing pop-up menu option in the displayed Get Info window.

owner privileges sharing privileges

This settable property returns a sharing privileges object for the container. See the sharing privileges class.

privileges inherited boolean

If this property is true, then the container has inherited its sharing properties from its own container or parent (as in a folder inheriting its sharing properties from its disk). File sharing has to be turned on to get this property, or the script will raise an error.

protected boolean

The sharing segment of a container’s Get Info window has a checkbox labeled “Can’t move, rename, or delete this item (locked).” If that item is checked, then this property is true. This property is settable too. If you try to use this property in a script when file sharing is not on, the script will raise an error.

shared boolean

If the container is being shared, then this property is true. If you try to use this property in a script when file sharing is not on, the script will raise an error.

sharing privileges

This class represents the privileges that a scripter can get or set for a container’s group, guest, or owner privileges. It has three properties, all returning true/false values. The following are sharing privileges properties:

sound file

This class represents the kind of sound files that are stored in the System suitcase file in the System Folder. They have names such as “Chu Toy,” “Laugh,” and “Uh oh.” They are used for purposes such as the alert sounds that you can set in the Sounds control panel in Mac OS 9. As a subclass of the file object, sound files have some file-related properties like name. Figure 15-8 shows a sound file icon.

The following is a sound file property:

special folders

The Finder can directly reference every one of the folders that are formally properties of the special folders class. In other words, you can use the following syntax to get an alias to the Extensions folder:

tell app "Finder" to get extensions folder as alias

This returns a value that looks like alias "Macintosh HD:System Folder:Extensions:". You have to make sure to include the word “folder” in the reference, as in extensions folder. But you do not have to capitalize these folders, even though their names are capitalized in the Finder. Or, you can get the file path to the startup disk:System Folder:Preferences directory as a string by coercing the file reference to a string or text, as in get preferences folder as text. This return value looks like “Macintosh HD:System Folder:Preferences:”. These special-folder references are very handy for navigating around an unfamiliar directory structure since you can use them as point of references. This example uses the system folder reference to see if the scripting addition Jon's Commands exists in the System Folder's Scripting Additions folder:

tell application "Finder"
   set sa to folder "scripting additions" of system folder
   set hasJons to exists (file "Jon's Commands" of sa)
end tell

The following are special folder properties:

system folder reference

The property returns a reference to the startup disk’s System Folder. You can get the reference with the syntax:

tell app "Finder" to get system
folder.
apple menu items folder reference

This property returns a reference to the Apple menu Items folder in the System Folder. You can get the reference with the syntax:

tell app "Finder" to get apple menu items
folder.
control panels folder reference

This property returns a reference to the System Folder’s Control Panels folder. You can get the reference with the syntax:

tell app "Finder" to get control panels folder.
extensions folder reference

The property returns a reference to the System Folder’s Extensions folder. You can get the reference with the syntax:

tell app "Finder" to get extensions folder
fonts folder reference

The property returns a reference to the System Folder’s Fonts folder. You can get the reference with the syntax:

tell app "Finder" to get fonts
folder
preferences folder reference

The property returns a reference to the System Folder’s Preferences folder. You can get the reference with the syntax:

tell app "Finder" to get preferences
folder
shutdown items folder reference

The property returns a reference to the System Folder’s Shutdown Items folder. You can get the reference with the syntax:

tell app "Finder" to get shutdown items folder

You can then use this reference to store an alias to an application or applet that you want to run before the computer shuts down, for instance.

startup items folder reference

The property returns a reference to the System Folder’s Startup Items folder. You can get the reference with the syntax:

tell app "Finder" to get startup items folder

You can then use this reference to store an alias to an application or applet that you want to run when the computer starts up.

temporary items folder reference

The temporary items folder is an invisible folder on the startup disk where the operating system and applications store temporary files. However, you can find out what is being stored in this folder with code such as:

tell app "Finder" to get entire contents of temporary items folder

This code returns a list of file references.

suitcase

A suitcase is a special kind of file that is designed to hold font files or desk-accessory files. suitcase is a subclass of file (even though it seems like a container) and the super class of the font suitcase and desk accessory suitcase classes. Therefore, suitcases have the relevant properties of their parent class file. See Figure 15-4 for a look at a desk accessory suitcase icon (for what it’s worth, the icons look like suitcases). The following is a suitcase element:

item

A suitcase contains stuff like font files, which are by extension items. You can find out the contents of a suitcase with the syntax: items of suitcase "DA suitcase".

trash-object

This is the class of the trash object, which is really a property of the Finder’s desktop object. But the Finder can refer to the trash object directly, without first using a desktop reference, as in:

tell application "Finder" to get warns before emptying of trash

This code gets a true/false value that determines whether a dialog box is displayed before trashed items are finally deleted. The Trash is a little barrel icon that is displayed by default in the lower right corner of the computer screen. The trash-object can contain anything that can be thrown away or deleted. The descriptions of these elements are the same as their class descriptions elsewhere in this chapter. The following are trash-object elements:

accessory suitcase
alias file
application file
clipping
container
desk accessory file
document file
file
folder
font file
font suitcase
internet location
item
package
sharable container
sound file
suitcase

The following is a trash-object property:

window

A Finder window is the window that opens up when you double-click a folder or disk to reveal their contents. Another example is the Get Info windows that open up when you select a file and choose Get Info from the Finder’s File menu or type Command-I. These windows should not be confused with the application windows, such as the word-processing window I am typing in now, or the tool-palette windows that are displayed by Photoshop. The following code will only return its own windows, not the application windows that you have open on your desktop:

tell app "Finder" to get windows
tell application "Finder"
   (* the equivalent of asking the Finder for 'all folders and disks that have 
open Finder windows' *)
   container of windows
end tell
(* Sample return value *)
{folder "actions" of application "Finder", disk "HFSgig" of application "Finder", 
startup disk of application "Finder"}

The following are window properties:

bounds bounding rectangle

This settable property represents the screen coordinates for the upper right and lower left corners of the window. The return value looks like {10,50,210,250}. A bounding rectangle class is really a list of four integers.

closeable boolean (read-only)

This property is true if you can close the window by clicking the box in its upper left corner.

collapsed boolean

This is true if the window is “collapsed” or pulled up like a window shade. In Mac OS 9, you can collapse a window by double-clicking its title bar (the bar along the top window border that contains the window’s title). This property does not apply to pop-up windows (in Mac OS 9, windows that are anchored to the bottom part of the screen and “pop up” when you click them).

floating boolean (read-only)

This value is false if the window is not a floating window (i.e., it always floats in front of other windows, whether or not you highlight it by clicking on the window). Rest assured this value will be false since no Finder windows are floating ones.

index integer

Finder windows are indexed, beginning with 1, from front to back. window 1, for example, inhabits the layer in front of window 2 and therefore covers window 2 if their regions overlap. The code fragment window index 1 is the same as the shorthand window 1. If no windows are open then trying to get window 1 will raise a script error, however.

modal boolean (read-only)

This will be false if the window is not modal. A modal window sits in front of other windows in the Finder and has to be dismissed (with a Cancel button, say) before you can click on other windows or menus.

name international text (read-only)

The name of the window is displayed in its title bar, if it has a title bar. You can refer to a window by its name without using the keyword name, as in get window "MyFolder".

popup boolean

This property is false if the window is not a pop-up window.

position point

This point property represents the upper left coordinate of the window, as in {10,50}.

pulled open boolean

This property returns true if the window is a pop-up window and it is open. If the window is not a pop-up, and you refer to its pulled open property, then you will raise a script error.

resizable boolean (read-only)

If you can change the size of the window by dragging the cursor along the lower right corner, as you can with a lot of Finder windows, then the window’s resizable is true.

titled boolean (read-only)

If the window has a title bar, then this property is true.

visible boolean (read-only)

If the window is open, its visible property returns true.

zoomable boolean (read-only)

If the window can be zoomed, or increased or decreased in size by clicking a button on the title bar, then this property returns true.

zoomed boolean

This property is false if the window is not zoomed to its full size (by clicking the title bar button adjacent to the button in the upper right order).

zoomed full size boolean

This true/false property can only be set (as in set zoomed full size of window 1 to true), and only applies to non-pop-up windows. If the script sets a window’s zoomed full size to true then the Finder will try to expand the window to fill the screen space.