Working with Finder and Inspector Windows
The Finder uses Finder windows to graphically navigate the filesystem.
Tip
The Mac OS X release renamed the file-viewer windows of the Mac OS X Public Beta to Finder windows, but the Finder dictionary also refers to Finder windows as “file-viewer windows,” so we will also occasionally use the file-viewer term.
Figure 32-2 shows a Finder window in column view.
With AppleScript, you can get references to any open Finder windows
(these refs look like “Finder window id
2” in Script Editor), and you can make new file
viewers and specify their target file or folder. The Finder
application
dictionary (which is called
“The Finder”) includes a
description of the new Finder window
class. A
Finder window
object inherits some of the
window’s properties (e.g., id
,
position
, bounds
) and has its
own target
attribute. The
target
is a reference to the deepest file or
folder selected in a Finder window
. For example,
if you were examining the contents of your
Documents directory in a Finder window
, then its target
property would
be:
folder "Documents" of folder "brucep" of folder "Users" of startup disk¬ of Application "Finder"
If you want a less unwieldy form of reference than the latter
target-return value, coerce the return value to a
string
(so it looks like "Mac OS
X:Users:brucep:Documents"
). Example 32-5 first gets a list
of
references to every open Finder window
(if there
are any). For each member of this list
(i.e., a
collection of Finder window
objects), ...
Get AppleScript in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.