Re: Rogue list?
Re: Rogue list?
- Subject: Re: Rogue list?
- From: Paul Berkowitz <email@hidden>
- Date: Sat, 12 May 2001 07:18:09 -0700
On 5/7/01 11:18 AM, "Chris Espinosa" <email@hidden> wrote:
>
> I'm running AS1.6 under 9.1. When I run the following:
>
>
>
> tell application "Finder"
>
> set myPath to path to me
>
> set myFolder to container of myPath
>
> set theClients to name of folders of myFolder
>
> end tell
>
> log class of theClients
>
> --if theClients = {} then set theClients to {}
>
> set end of theClients to "New"
>
> theClients
>
>
>
> I get an error that I "Can't set end of {} to "New"." But when I
>
> uncomment
>
> the line before, it works. Any explanations?
>
>
Yes, a simple one.
>
>
When the Finder returns an empty value collective Get Data operation
>
(anything with a plural anywhere in the direct object, such as your
>
"name of folders of myFolder"), it doesn't return an empty list, it
>
returns an empty *record*. Which looks and prints and smells like an
>
empty list, and compares correctly to an empty list, but can't do
>
list-like things, like having its end set. Your commented-out line is
>
unfortunately the correct workaround, as there's no way to specify an
>
empty record in AppleScript itself.
<later reply from Chris Espinosa: >
>
> And why does it log the class as list instead of record in OS 9?
>
>
That we haven't figured out yet...
>
>
Chris
Could we go back to first principles here?
WHY does the Finder return an empty record rather than an empty list when
it's asked for a direct object including a plural? I've confirmed this with
a simple 'set theFolders to folders of myFolder':
tell application "Finder"
set myPath to path to me
set myFolder to container of myPath
set theFolders to folders of myFolder -- no subfolders in fact
end tell
log class of theFolders -- (*list*)
set end of theFolders to "New"
--> ERROR: Can't set end of {} to "New".
[BTW, my AppleScript formatting shows the {} brackets as an application
keyword!]
I purposely say 'the Finder' rather than 'AppleScript' returns an empty
record, even though the error message above does not refer to the Finder by
name (as in 'Finder got an error'), because AppleScript DOES NOT error with
plurals as direct object in some other applications:
tell application "Microsoft Entourage"
set myFolder to folder "Test" -- an empty message folder
set theMsgs to messages of myFolder -- {}
end tell
set end of theMsgs to "New"
theMsgs
--> {"New"}
(If I try what Shane did, namely use a property of the plural direct object
when there are none:
tell application "Microsoft Entourage"
set myFolder to folder "Test"
set theClients to subject of messages of myFolder
end tell
set end of theClients to "New"
theClients
I get the error instead where you'd expect, namely when asking for the
property of an empty list:
set theClients to subject of messages of myFolder
--> Microsoft Entourage got an error: Can't get subject of every message of
folder id 146.
Perhaps the reason that the class of 'theFolders' in the Finder example
above (and Shane's original 'theClients') is logged as list rather than
record is something to do with the fact that asking for 'folders', or 'name
of folders' _should_ produce a list and not a record? Is this merely (yet)
another Finder scripting bug rather than something more basic in
AppleScript? Or is that too simplistic?
--
Paul Berkowitz