In summary, getting to know Finder
objects such as the application and
item classes is a tremendous benefit to scripters.
The following section describes the 36 classes that are part of the
Finder dictionary in Mac OS 9. Remember that an object can have more
than one of its elements, such as the Finder
application's container windows, but only one value
for each of its properties. If you want to get a
list of all of an object's values
for a certain element, enclose the element in plural form in a
tell statement targeting the object, as in the
following (which returns all open container windows in a
list):
tell app "Finder" to container windows It only sounds weird because I've left out the
unnecessary get part of get
container windows. Forthwith are all of our Finder
classes.
Dictionary classes
- alias file
This class represents an alias, which is a
file that points to another
file. For example, if you select a file called
myfile and type Command-M, then this action creates an
alias file in the same folder with the name
"myfile alias" in italics. The
following is an alias file property:
- original item reference
This property returns the original item that the
alias points to. For instance, if you make an
alias file that opens Photoshop 5.5 when you
double-click it, then this alias file's
original item property returns:
file "Adobe Photoshop 5.5" of folder "Adobe Photoshop 5.5" of¬ startup
disk of application "Finder"
- alias list
This is a class that represents a
list of aliases (surprise, surprise). It can be
handy to use this class with the as keyword to
convert a bunch of file or
folder references to aliases. Why would you want a
list of aliases instead of file
object references? One reason is that it is very easy to get the path
of an alias in a readable form; you just coerce
the alias to a text type, as
in:
set thePath to myalias as text
This code returns a string that gives you the full
path on the computer to the file. Overall, the reference
alias "HFSA2gig:1wordfiles:fol1:file.1" is more
intuitive to me than the reference:
file "file.1" of folder "fol1" of folder "1wordfiles" of disk¬ "HFSA2gig"
To coerce a list of file
references to an alias list, you would use code
such as:
set myAlls to fileList as alias list
- 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:
- accessory process
An accessory process is an
application such as Calculator or Note Pad that is
installed with the Mac system. Use the code every
accessory process to get a
list of the running accessory processes. See the
accessory process class description.
- accessory suitcase
This is a type of suitcase that can only hold
desk accessory files. See the
suitcase and accessory suitcase
class descriptions.
- alias file
The command every alias file returns all the alias
files that currently reside on the desktop. See the alias
file class description.
- application file
These are files that launch an application, including an AppleScript
applet, when double-clicked. The command application
files, when sent to the Finder, returns all of the app
files that reside on the desktop (application
processes will return all the running programs, on the
other hand). See the application file and
application process class descriptions.
- application process
These elements are the software programs, including some of the
invisible system programs, that are running on the computer at the
moment. See the application process class
description.
- clipping window
These are the windows that the Finder displays when you double-click
on a clipping file. See the clipping window class
description.
- clipping
A clipping is a (usually) small file that can be
dragged into programs that support drag-and-drop behavior. Get every
clipping on the desktop with code such as:
tell app "Finder" to clippings
See the clipping class description.
- container window
This is a more specialized type of window that
inherits from the window class. If you send the
Finder a command that looks like container
windows, the return value is a list of windows. An
example return value is:
{container window of folder "chap15Scripts" of application "Finder"}
See the container window class description.
- container
A container is a super class for other objects
such as disks, folders, and sharable containers. You can encompass
all of the desktop objects that can contain something with code such
as:
tell app "Finder" to get containers
- content space
This is a broad abstraction of the window class
that includes all open windows and the desktop. If you use code such
as items of content spaces,
then you will get a possibly large list of
references to every folder and
file on the desktop and in any open windows. If
you have a disk window open, this will be a very
large list.
- desk accessory file
desk accessory files are the files that you would
double-click to open programs such as Calculator or the Chooser. See
the desk accessory file class
description.
- disk
A disk is a type of sharable
container. You can get all of the disks mounted on the
desktop, including the computer's own disks and
network volumes, using code such as:
tell app "Finder" to get disks
This returns a list of disk
references that looks like:
{disk "B2gig", disk "scratch_disk", startup disk, disk "Z2gig"}
- document file
Getting the Finder's document
file elements only returns text, word-processing, and image
files, not alias, clipping, and
other file types. Use code such as:
tell app "Finder" to get document files
This can be a more efficient way to pull word-processing files out of
a very large folder, rather than getting all files first into a giant
list then sifting through them. See the
document file class description.
- file
file is an element that encompasses all types of
files, from application and alias files to document files. If you
want to distinguish the files from the folders in a directory, then
you can use code such as:
tell app "Finder" to get files of folder "today"
See the file class description.
- folder
If you send the Finder a getfolders or geteveryfolder, command then AppleScript returns references to
all folders and disks on the desktop. In this case, a
disk is considered a specialized kind of folder,
even though its dictionary definition indicates that disk inherits
from the sharable container
class (just as folder objects inherit from the
sharable container class).
- font file
This file is usually located in a font
suitcase, but you can pull it out of the suitcase if you
want and take a look at it. An example of a font
file is Verdana (bold,
italic) inside the Verdana suitcase.
See the font file class
description.
- font suitcase
These are suitcases that can only contain
font files. See the font
suitcase class description. This code gets the
Finder's hundreds of font
suitcases from inside the Fonts folder
in the System Folder :
get font suitcases of fonts folder
- information window
This is the specialized window type that opens up
when you select a file, folder,
or disk and type Command-I.
See the information window
class description.
- internet location
This element is a file that contains an Internet
location. See the internet location file class
description.
- item
An item is a super class for several child objects
such as aliases, clippings, disks, files, and folders. If you want an
indiscriminate (and large) list of all the stuff
on the desktop, use code such as:
tell app "Finder" to get items
See the item class description.
- package
A package is a special kind of
folder that is designed to contain an application,
an alias to the program, and perhaps support files
such as help files and libraries. The following web site describes
packages: http://developer.apple.com/technotes/tn/tn1188.html.
See the package class description.
- process
This class is the parent class for other types of processes, such as
application processes and accessory processes. The following code
fetches a list of the currently running processes
on the machine:
tell app "Finder" to get processes
A sample return value is:
{process "BBEdit 5.1" of application "Finder"}
(although the actual return value contains a dozen or more
process objects). See the
process class description.
- sharable container
This is the parent class for a folder or
disk, for instance, that has file-sharing related
properties such as an owner and a
shared
true/false value. The code
phrase tell app
"Finder" to sharable
containers returns a list of
these desktop objects. See the sharable container
class description.
- sound file
This element represents files that contain sound data. An example
Finder reference to a sound file is:
item "ChuToy" of suitcase "System" of folder "System Folder"¬
of startup disk of application "Finder"
You can get the sound files that provide your
system's sound effects with code such as:
get sound files of suitcase
"system" of system folder.
See the sound file class description.
- suitcase
A suitcase is the parent class for accessory
suitcases and font suitcases.
- window
This class is what you expect it to be: a window
that opens when you double-click a folder or
disk. It is also the super class to specialized
window types such as information windows,
preferences windows, and clipping windows (which inherit the
properties of the window class). Using code such
as:
tell app "Finder" to get windows
only returns Finder windows, however, not application windows such as
Script Editor's or BBEdit's.
Therefore, you can have a desktop full of open application windows,
and get windows can still return an empty
list. See the window class
description.
The following
are application properties:
- about this computer list of processes (read-only)
This property returns a list of running processes on the computer. It
is associated with the About This Computer dialog window from the Mac
OS 9 Apple menu. You then can get memory-use information by querying
each of the returned process objects. See the
process class description.
- clipboard reference (read-only)
This property returns the Finder's clipboard window.
You can open this window by telling the Finder to open
clipboard. The clipboard contains the
contents of anything that the Finder or another application has
selected and copied.
- desktop (read-only)
desktop returns a desktop
object value that represents your desktop. See the
desktop object class description. One easy way to
get the text path to a computer's desktop is to use
this code phrase inside of a Finder tell block:
(path to desktop as text). This returns a
string such as "Macintosh
HD:Desktop Folder:."
- execution state constant
The execution state property
returns on eof the following six constants:
restarting, starting
up, running,
rebuilding desktop,
copying, or quitting. This
property is only available on the systems that are running OS 9.1 or
later. Execution state allows the script to determine whether it has
been called as part of a computer shutdown or restart, for instance.
- file sharing boolean
This is a true/false value
indicating whether file sharing is turned on. You can turn file
sharing off or vice versa with code such as:
set file sharing to false
- Finder preferences preferences (read-only)
This property returns a preferences object, from
which you can get all kinds of information about the preferences you
are using for viewing files and folders (see the
preferences class description). For example, if
you want to find out whether a file-list view in a folder includes
the file's comments, use code such as:
shows comments
of Finder preferences (a
true/false value).
This is the equivalent of going to the Finder's
View:View Options... menu.
- frontmost boolean
If the Finder is the frontmost application then this property returns
true. You can make the Finder the frontmost
application by telling the Finder to activate or
by using syntax such as:
tell app "Finder" to set frontmost to true
- insertion location reference (read-only)
This property returns a reference to the folder in which a new
untitled folder would appear if you typed
Command-N on the keyboard. It is an indication
of which Finder window (i.e., the desktop itself or an open window on
a disk) is active at the moment.
- largest free block integer (read-only)
This handy property returns the number of bytes that represents the
largest free block of RAM that can be used to open an application.
This information is also available from the Apple
menu's About This Computer window. You can get the
largest free block in megabytes by dividing this property twice by
1024, as in:
(largest free block / 1024 /1024)
- name international text (read-only)
This property returns the Finder's text name,
"Finder."
- product version international text (read-only)
This property returns the following string on my
machine: "9.0.4 PowerPC Enabler
9.0.4". See "Finding out the Operating
System Version" in Chapter 14.
- 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.
- version international text (read-only)
This returns the version of the Finder, such as
"9.0."
- visible boolean
If the Finder layer, your desktop, is visible, then this property
returns true. Setting it to
true when you have a bunch of application windows
(such as Photoshop palettes or word-processing windows) covering up
the Finder has no effect, however. In other words, setting
visible to true will not reveal
the Finder and push the other windows out of the way.
- 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:
- accepts high level events boolean (read-only)
If the program accepts high-level events such as Apple events, then
this property returns true.
- has scripting terminology boolean (read-only)
If the application has a dictionary that you can view in Script
Editor, for example, then this property is true.
Version 1.4.3 of Script Editor, however, returns
false for this property.
- 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.
- preferred 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 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.
- suggested size integer (read-only)
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.
- application process
When an application file is executed and runs on
your machine, it becomes one of the application processes. This is a
child object of the process class and thus
inherits process properties, such as
name, file
type, and creator type. The
following example gets the name and
creator type of all the current application
processes in two separate lists. The bottom of the example shows a
sample return value. The first list is all the
names, and the second is the creator types:
tell application "Finder"
{name, creator type} of application processes
end tell
(* return value sample *)
{{"Control Strip Extension", "DAVE Sharing Extension", "Folder
Actions", "HP Background", "OSA Menu Lite", "Time Synchronizer", "Web
Sharing Extension", "ShareWay IP Personal Bgnd", "Outlook Express",
"Adobe® Photoshop® 5.5", "BBEdit 5.1", "FileMaker Pro", "StuffIt
Deluxe™", "Microsoft Word", "Script Editor"}, {<<class sdev>>, <<class
TSSS>>, <<class ssrv>>, <<class HPBG>>, <<class osaL>>, <<class tims>>, <<class
wbsh>>, <<class aIPG>>, <<class MSNM>>, <<class 8BIM>>, <<class R*ch>>, <<class
FMP3>>, <<class SIT!>>, <<class MSWD>>, <<class ToyS>>}}
- application file
This returns the file that is associated with the
application process as an application
file object. See the application file
class description.
- clipping
A clipping is a file that is created automatically
when you drag text from a document window, for instance, to the
desktop. You can then drag the clipping from the
desktop to another document window to reproduce the text. For
example, you can drag an address from a word-processing document on
to the desktop and create a clipping, which can
then be dropped onto an email message window. Figure 15-3 shows the clipping file
icon. A clipping is a subclass of the
file class, so it has some file
properties such as creator type and file
type.
- clipping window
This class represents a Finder window that is produced when you
double-click on a clipping. It is a subclass of
window, and thus has some
window properties such as
bounds (which is a list of
coordinates such as {525, 47, 825, 247} that represent the screen
positions of the upper left and lower right window corners). See the
window class description.
- 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:
- completely expanded boolean
You can completely expand a container such as a
folder in "list" view by using the
command:
set completely expanded of folder "today" to true
This command opens up the disclosure triangles in the
folder's list view to show the contents of all
folders and nested folders.
- entire contents reference
This very handy property returns the entire
contents, nested folders and everything, of a
container. However, this property can be very
unreliable, according to an AppleScript veteran who reviewed this
book, particularly when dealing with a relatively large number of
items in a container. In some of these cases, depending on unknown
factors, the entire contents property returns
incomplete results but does not raise an error.
- expandable boolean (read-only)
If the container can be expanded as an outline,
then this property is true.
- expanded boolean
If the container, like a
folder, is expanded so that the contents of
folders are listed, then this property is true. It
is settable if the container is in
"list" view (i.e.,
View:as List in the Finder menu).
- icon size integer or mini/small/large
You can specify the size of icons in the container
as either an integer or one of the constants
mini, small, or
large. The integer values are
large (0), small (1), and
mini (2).
- selection reference
The items that are selected in the container, if
any, are returned as a list of references when
this property is invoked. For example:
get selection of container "today"
A return value might be:
{file "find_objmodel.psd" of folder "chap15Scripts" of application "Finder"}
- 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:
- button view arrangement constant
This property returns 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.
- calculates folder sizes boolean
If the size of contained folders are displayed in the
container window, this property is
true. You can set it for the applicable container
windows (in other words, not for suitcase windows).
- container reference (read-only)
This property returns a reference to the
container associated with this window.
- has custom view settings boolean
If this container window uses the default view
settings from the Finder preferences window then this property is
false.
- item reference (read-only)
This property returns a reference to the
item associated with this window.
- previous list view constant (read-only)
This property returns one of the column names from a folder in list
view, such as Name, Date Modified, or Size.
- shows creation date boolean
This is a true/false value
indicating whether the creation-date column is showing in the folder
or disk window. The property is settable when the container
window is in list view.
- shows kind boolean
This is a true/false value
indicating whether the kind column is showing in the folder or disk
window. The property is settable when the container
window is in list view.
- shows label boolean
This is a true/false value
indicating whether the label column is showing in the folder or disk
window. The property is settable when the container
window is in list view.
- shows modification date boolean
This is a true/false value
indicating whether the Date Modified column is showing in the folder
or disk window. The property is settable when the container
window is in list view.
- shows size boolean
This is a true/false value
indicating whether the size column is showing in the folder or disk
window. The property is settable when the container
window is in list view.
- shows version boolean
This is a true/false value
indicating whether the version column is showing in the folder or
disk window. The property is settable when the container
window is in list view.
- sort direction normal/reversed
If you set the sort direction to reversed, then
the name column for instance lists filenames in reverse alphabetical
order, and the Date-Modified column lists the most recently modified
files last.
- spatial view arrangement constant
This property determines how icons are arranged in a
container window. It can be set
to 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.
- uses relative dates boolean
If this is set to true then the Date Modified
column uses relative dates like today and
yesterday.
- view constant
This property returns the currently selected column, such as Name or
Date Modified.
- content space
The following code returns all open Finder windows and the desktop:
tell app "Finder" to get content spaces
There are easier ways to get a reference to the desktop, such as
through the Finder's desktop
property. Use the phrase (path to desktop as text)
to get any Mac's file path to the desktop (as long
as that machine has the path to scripting
addition installed).
- desk accessory file
The files that launch the Calculator and the Chooser are considered
desk accessory files. See the
desk accessory process description.
- desk accessory process
If you launch the Calculator process class or the
Chooser, they are considered desk accessory
processes and inherit some of their properties. For
example, if the Chooser is running then the code:
tell app "Finder" to get desk accessory processes
returns a value that looks like:
{process "Chooser" of application "Finder"}
The following are desk accessory properties:
- desk accessory file reference (read-only)
This property returns the desk accessory file that
is associated with the process.
- desk accessory suitcase
This is a special kind of suitcase for
desk accessory
files. A suitcase is like a
folder (even though it is a file subclass!), but
it can only contain certain types of files like font files. You will
get an icon on the desktop that looks like Figure 15-4 if you tell the Finder to make new
desk accessory suitcase (it is created on the desktop by
default because the latter code phrase did not specify a location
with the make command).
The following is a desk accessory elements:
- item
If you want to get the contents of a desk
accessory (DA) suitcase stored in a
da_suit variable, for example, then
items of da_suit returns a list
of items or an empty list if the
suitcase is empty.
- desktop object
This is the object that is returned when you get the Finder
application's desktop property.
Actually, the desktop is the
Finder's default property, so you can use syntax
such as in the following example to get all the alias files on the
desktop, without even referring to the desktop
property:
tell application "Finder"
(* returns all the alias files on the desktop in a list *)
alias files
end tell
The definitions of the following desktop object
elements are the same as their class descriptions in this chapter:
- accessory suitcase
- alias file
- application file
- clipping
- container
- desk accessory file
- disk
- document file
- file
- folder
- font file
- font suitcase
- internet location
- item
- package
- sharable container
- sound file
- suitcase
The following is a desktop object property:
- startup disk disk
Since the desktop is the Finder's
default property and does not have to be explicitly invoked, every
time you refer to startup disk in a Finder
tell statement you get this
disk object as a return value. You can then find
out valuable things about the startup disk, such as how much free
space is left on it: free space of startup disk. See the
disk class description.
The Startup Disk control panel
is scriptable in Mac OS 9.1. For example, the startup disk
alias property returns an alias to the
disk that contains the System Folder from which the computer started
up. You can also get the value of the System Folder from which the
computer started up with the startup system folder
alias property. Startup Disk's dictionary
also has two boolean properties: netboot and
localboot (a true/false value
indicting whether the computer will boot from a local disk).
Localboot did not return any value in my testing.
NetBoot is a service provided by Mac OS X server that allows Power
Mac computers and PowerBooks to login and boot directly from a server
rather than a local hard disk. See the technical note at http://developer.apple.com/technotes/tn/tn1151.html.
In Script Editor, choose File Open Dictionary to
see the Startup Disk's dictionary. Chapter 1 and Chapter 2 of this book
describe an application's or control
panel's dictionary.
|
- 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:
- capacity integer (read-only)
This property returns the total number of bytes on the
disk, including the used and free space. You can
get this figure in kilobytes by using (capacity /
1024) and in megabytes by using (capacity / 1024
/ 1024). The parentheses are not
required but make equations easier to read and perhaps comprehend.
- ejectable boolean (read-only)
If the disk is ejectable like a floppy or zip
disk, then this property returns true.
- free space integer (read-only)
This property represents the number of bytes of free space on the
disk. To get the free space in kilobytes use:
(free space / 1024); in megabytes (free space / 1024 /1024)
- local volume boolean (read-only)
You can determine whether the disk is a local or
network disk with this
true/false property (if
it's true then it is local, like
one of your hard disks).
- startup boolean (read-only)
If the disk is the startup or boot disk, then this
property is true. An easy way to get a reference
to the startup disk is by using the following code (or something
similar to it):
tell app "Finder" to get name of startup disk
- 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:
- file type class type
This property is the four-character code for the
file's file type. An example is
'APPL' for an application file.
- creator type class type
This property is the four-character code for the
file's creator type.
- locked boolean
If the file is locked (by checking the locked
checkbox in the file's Get Info window, which is
displayed by selecting the file and typing
Command-I), then you cannot save any changes to
it. You can set a file's locked
property with syntax such as:
set locked of file "chap15" to true
- stationery boolean
If the file is a "stationery
pad" or a template for making new files, then this
property is true.
- product version international text
This is the product version in the
file's Get Info window. This can be an empty
string (" ") if
there is no valid product version number for the
file.
- version international text
This is the version at the bottom of the
file's Get Info window. This can be an empty
string (" ") if
there is no valid version.
- 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:
- location international text (read-only)
This property returns the web page location or Uniform Resource
Locator (URL), as in http://www.apple.com:
tell application "Finder"
(* sample return value: {"http://www.apple.com"} *)
location of (internet location files of folder "favorites"¬
of system folder)
-- will return a list type since the code gets several files
end tell
- 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 difference between an
application process and an application
file is that a process object is not
created unless a process is actually running on
the computer (i.e., you have double-clicked an application and the
operating system loads the software into memory and displays its
windows/menus). You get can the properties of any
application file that is stored on disk, however,
whether or not it is open on the computer. For example, if Photoshop
is not running at the time but is on your computer, then getting all
of the Finder's application processes will not
reveal an "Adobe® Photoshop®
5.5" process.
|
|
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:
- make changes boolean
If this property is true then the group or guest
can make changes to the shared object, like a folder or file. You can
refer to this property in the following manner (inside a
tell statement targeting the Finder):
set make changes of folder "today"'s group privileges to
false
- see files boolean
If the sharable container contains files (such as
files inside of a folder), then the scripter can use this property to
make the files visible or invisible to the users who are sharing the
folder. Here is some sample code:
set see files of folder "today"'s group privileges to false
You cannot set or get this property unless file sharing has been
turned on.
- see folders boolean
If the sharable container
contains folders (such as folders inside of a folder), then the
scripter can use this property to make the folders visible or
invisible to the users sharing the folder. Here is some sample code:
set see folders of folder "today"'s group privileges to false
You cannot set or get this property unless file sharing has been
turned on:
tell application "Finder"
set see files of group privileges of folder "today" to true
set see folders of group privileges of folder "today" to true
set make changes of group privileges of folder "today" to false
end tell
- 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:
- sound data
This property is designed to return the sound data
for a sound file. You have to pull the
sound file or copy it out of the
System suitcase to retrieve
its sound data, however. The return value of the
sound data, which is in
raw-data format, is a giant series of hexadecimal numbers that
partially look like this:
<<data snd 000100010005000000C0000180510000000000140000000000000002AC44...>>
Chapter 3 describes raw data
value types, which are delimited by guillemet characters
(<< >>).
- 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:
- warns before emptying boolean
The trash-object inherits some relevant properties
from its container parent class, such as
entire contents, which gives you a
list of references to whatever is in the trash.
The trash-object has one of its own properties.
You can suppress the dialog box that displays before an item is
deleted from the trash with this syntax:
set warns before emptying of trash to false
- 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
|
A
Finder window is not a container class, so you
cannot use code such as entire contents of window
1 to get a window's contents. The
following example shows a better way to get the contents of a window.
It gets the container property of each
container window that is open
in the Finder. container window is a subclass of
window. Therefore, the
windows command returns all
container windows (i.e., any
open windows attached to a container like a
folder), each of which has a
container property that identifies the
window's disk or
folder.
|
|
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.
|