Re: "a reference to"
Re: "a reference to"
- Subject: Re: "a reference to"
- From: Mark Alldritt <email@hidden>
- Date: Thu, 10 Jan 2008 15:14:19 -0800
- Thread-topic: "a reference to"
Hi,
>> 2. [Implicit get's] invisible nature means that users cannot
>> obviously see - and thereby understand - why their code fails in
>> some cases, because their experience of the common-case behaviour
>> has given them a faulty understanding of how AppleScript and Apple
>> event IPC actually work.
>
>
> The get events do show up in the event log, which should help. One
> shortcoming is that the event log only logs events and nothing else,
> so it can be difficult to correlate events to what's going on in the
> script.
>
>
> In Michelle's original script, the event log shows
>
> get every person of group "foo"
>
> with the result
>
> {person id ..., person id ...}
>
> followed by the error
>
> Can't get email 1 of {person id ..., person id ...}
>
> which indicates that it can't get "email 1" of the list of person ids.
>
>
> In her modified script that works, the event log shows
>
> get label of email 1 of every person of group "foo"
>
> with the result
>
> {"foo", "bar", "baz", ...}
>
> indicating a list of labels.
>
>
> Perhaps one problem is that it can take some time to learn the
> relationship between scripts and events, including the fact that the
> text "{foo, bar}" in the event log represents an actual list object
> rather than the conceptual collection of objects within the target
> application?
>
> It would be interesting to know whether there's a clearer way to
> indicate to the scripter what's going on in the event log.
With respect, if the user is expected to go to the event log to figure out
what AS is actually doing, we are already lost. Sure, the event log does
give a definitive listing of what actually happened, but I find that users
really don't understand *why* the code they typed into AppleScript sometimes
generates *different* AppleEvents.
I think that has' example is particularly instructive:
> tell application "Finder"
> get text 1 thru 3 of name of home -- doesn't work
> end tell
>
> vs.
>
> tell application "Finder"
> get text 1 thru 3 of (get name of home) -- works
> end tell
In the first example, the event log would show 'get text 1 thru 3 of name of
home'. This does not help the user figure out why its failing. The event
matches the statement. The event is valid, and matches the user's
expectation.
The technical failure here is in the Finder - it cannot resolve the 'text 1
through 3 of "string"' portion of the object reference. AppleScript is
simply doing what has been told to do. Of course if AppleScript actually
paid attention to the dictionary it would know that 'name of home' is the
extent of the external object reference (since its value is a string, and
not a text object), but that's a different matter (of course the fact that
'sdef' meta-data uses the same type name for text objects and strings does
not help).
When I developed the scripting interface for Script Debugger 3 (and later
Illustrator 7), we solved a lot of these problems by making the application
able to resolve text suite, list and record references within the *values*
returned for properties and event results. This allowed users to write
things like:
name of item 1 of printer list of document x
Normally, you would have to say 'name of item 1 of (get printer list of
document x)' to force AppleScript generate the correct Get event, and then
let AppleScript do what it knows how to do with the resulting list of
records.
If Cocoa Scripting would take on this task, developers would get this for
free and users would get a much less confusing scripting experience. It may
not solve all the reference issues, but I believe it would be a 90% solution
(at least for Cocoa applications). You could then close the rest of the
loop by making AppleScript actually validate an object reference against the
dictionary - at least generating an error/warning when things are not
explicit.
Cheers
-Mark
------------------------------------------------------------------------
Mark Alldritt Late Night Software Ltd.
Phone: 250-380-1725 Script Debugger 4.0 - AppleScript IDE
WEB: http://www.latenightsw.com/ FaceSpan 4.3 - AppleScript RAD
Affrus 1.0 - Perl Debugging
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden