Re: Please explain this!?
Re: Please explain this!?
- Subject: Re: Please explain this!?
- From: Paul Berkowitz <email@hidden>
- Date: Fri, 23 Nov 2001 07:44:47 -0800
On 11/23/01 3:26 AM, "Harald E Brandt" <email@hidden> wrote:
>
tell application "Finder" to (folders in extensions folder whose name starts
>
with "a")
>
-- {folder "ActiveX Controls" of folder "Extensions" of folder "System
>
Folder" of startup disk of application "Finder"} --Fine, that's expected. Now,
>
pick that folder:
>
>
tell application "Finder" to item 1 of (folders in extensions folder whose
>
name starts with "a")
>
-- {file "AdobePS" of folder "Extensions" of folder "System Folder" of
>
startup disk of application "Finder"}
>
>
--What??? A file! That should be impossible!?
>
--I'm picking the first in a list of folders, and expect a folder!
>
--Compare with:
>
>
tell application "Finder"
>
set theList to (folders in extensions folder whose name starts with "a")
>
item 1 of theList
>
end tell
>
-- folder "ActiveX Controls" of folder "Extensions" of folder "System Folder"
>
of startup disk of application "Finder"
>
--That's what I wanted (although my real scripts are not about extension
>
folder, but the principle error is the same)
>
>
>
My scripts run havoc! I need to understand what the hell is going on with
>
filtering!!
Take a look at the Finder Dictionary:
Class folder: A folder
Plural form:
folders
Elements:
item by numeric index, by name
'item' is a Finder keyword. In the case of a folder, it means anything that
you can find inside a folder - any element of a folder, namely other folders
and files. Inside a Finder tell block, its own keywords will take precedence
over any other possible reading of any keyword, including 'item' of an
AppleScript list. (The same thing happens, e.g., for 'file' inside an
Outlook Express tell block: it has a special OE meaning as a property of a
message attachment and will error if you try to use it as a regular
AppleScript keyword.)
In your second example, theList is unequivocally an AppleScript list, not a
Finder construct, so you get list item, not Finder item. Even clearer would
be to take it out of the Finder tell block after you've done what you need:
tell application "Finder"
set theList to (folders in extensions folder whose name starts with "a")
end tell
item 1 of theList -- you'll get it in alias form now
--alias "Hard Disk:System Folder:Extensions:ActiveXControls:"
In your first example there's no error. That's how AppleScript is supposed
to behave when there is a namespace conflict: the application tell block
term rules. To get it in one line without using an interceding variable, try
using the explicit 'get':
tell application "Finder" to item 1 of (get folders in extensions folder
whose name starts with "a")
I'm in OS X now, and can't test this - not only are there no "special
folder" like extensions - instead you use the 'path to' addition, but
'whose' filters aren't available for 'folder'. (They are available for
'item', but even that doesn't seem to be working at the moment.) So I
apologize if that 'get' doesn't work, but I think it should (an unsafe
assumption sometimes where the Finder is concerned.)
--
Paul Berkowitz