Re: Please explain this!? More....
Re: Please explain this!? More....
- Subject: Re: Please explain this!? More....
- From: Hugh Dixon <email@hidden>
- Date: Fri, 23 Nov 2001 15:48:24 +0000
On 23/11/01 1:07 pm, Harald E Brandt of email@hidden wrote in whole or
in part:
>
Quote from AppleScript Language Guide:
>
"The value of an Every Element reference is a list of the objects in the
>
container."
The value, and not the class.
>
>
Now try:
>
tell application "Finder" to class of (every file in control panels folder)
>
-- {application file, control panel, control panel, control, control,
>
control, <and many more>}
>
The above violates AppleScript Language Guide!? It' not class list!
>
What are those braces?
>
The result of Every Element is thus not a list but a new, to me unknown,
>
class. (Set of classes?)
The above tells the Finder to return the class of every file in the Control
Panels folder. Quite reasonably IMHO, it returns all of those classes as a
list. Some of the files in the Control Panels Folder are control panels,
some are application files. These are special classes of file (see the
Finder dictionary). What you are looking at is a list of classes. Hence the
braces. The objects in the container (the list) are the classes (the special
file types).
>
Compare with:
>
tell application "Finder" to class of ((every file in control panels folder)
>
as list)
>
-- list
>
Which is what I expected from the first statement.
Now you are telling the Finder to return the class of that list. Which as
you rightly expect, is list.
>
It can also be done with:
>
tell application "Finder" to class of (get every file in control panels
>
folder)
>
-- list --(i.e that 'get' changed it all somehow!?)
Here you are effectively combining two commands in one line, and the Finder
works outwards from inside the brackets. The first command is
Tell application "Finder" to get every file of control panels folder
This returns a long list of Finder references.
Then (as part of the same line) you say
Tell application "Finder" to get class of (that list)
Which is, naturally enough, class list.
>
>
I CAN do:
>
tell application "Finder" to name of ((folders whose name starts with "a") in
>
extensions folder)
>
-- "ActiveX Controls"
Confirmed. But this is because you are working with the special case of
there only being one folder in the Extensions Folder whose name begins with
"a". Create another folder in the Extensions Folder and call in "Abba". Now
run the above script. You'll get a list. The Finder is silently coercing the
single-item list to a string. This may be a bug or a feature, but it
doesn't (AFAIK) stop people from using AppleScript.
>
>
I can also do:
>
tell application "Finder"
>
set name of ((folders whose name starts with "a") in extensions folder) to
>
"NiceTry"
>
end tell
This approach, if it works at all, is only going to work in that special
case of there being one folder whose name begins with "a" in the Extensions
Folder. If your folder "Abba" is still in there, the Finder will rename the
first file and then error. What do you want to do?
>
>
But I CANNOT do:
>
tell application "Finder"
>
set f to ((folders whose name starts with "a") in extensions folder)
>
set name of f to "NiceTry"
>
end tell
>
--Yields error!
Because f is a list, and lists don't have names, and even if they did the
Finder wouldn't be interested in changing them.
>
With semantics like this, I can't program!!
I'm sure you can!
Hugh
**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.
This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.
www.mimesweeper.com
**********************************************************************