Re: Unwinding the containment hierarchy of a reference
Re: Unwinding the containment hierarchy of a reference
- Subject: Re: Unwinding the containment hierarchy of a reference
- From: Michael Terry <email@hidden>
- Date: Wed, 08 Dec 2004 14:53:26 -0800
On Tuesday, December 07, 2004, at 11:42PM, Paul Berkowitz <email@hidden> wrote:
>On 12/7/04 8:25 PM, "Scott Babcock" <email@hidden> wrote:
>
>> Thanks for all of the comments on this.
>>
>> Paul's point about containment is well taken. A given object may be
>> directly contained by more than one container object, as amply
>> demonstrated by Word's [text range] class and its descendants.
>>
>> For my purposes, converting a reference into a string that describes the
>> reference is sufficient. Thanks to Michael Terry, I have a usable
>> (albeit ugly) solution:
<snip>
>> Can you say "ugly hack"? I knew you could... ;)
>
>Can you explain how this gets you what you were looking for, Scott? It gets
>you a string, not a set of objects. It seems you want to be able to be
>introspective - to parse the containment chain of a [selected?] object. How
>will you get from the string "word 12 of document 2 of application
>\"TextEdit\"" to the separate objects word 12 and document 2. Or is this
>just for humans to read? Doing a 'run script' on the whole script just puts
>you back where you started. Otherwise you'd have to know to use 'of' the
>separate the objects. That might actually work, since even using alternate
>syntax:
<snip>
> You can't do a 'run script' on the separate elements since some don't
>resolve as incomplete ("word 12") and those that do (elements of the
>application) tack on 'of application "TextEdit". ("TextEdit" itself results
>in 'current application'.)
>
>But if strings are good enough, I guess you've got your bits.
>
>What purpose does this serve? Something along the lines of what Chris is
>describing? Or maybe a way of pinpointing errors without running a script in
>a script editor?
When I suggested using the error text to Scott, I didn't lay it all out for him, but he understood immediately that he would use 'run script' to reconstruct the object references. If you've got an object specifier, and you can get it as a string, then you can take whatever pains you want to parse it and turn pieces of it back into valid object specifiers using 'run script'. If you wanted, you could create a list of the parent objects. If you wanted to create a more universally useful handler, and have it work with multiple applications, that'd require some extra work. For example, some objects might be specified with a name reference, so could contain the " of " string.
As for why Scott wanted to do it, I didn't ask. I normally assume folks know what they're doing or have so much invested in their current approach that redirecting them will cause more hardship then it's worth. I know I personally get irritated when I ask a question only to be told I'm wrong to be asking it.
In general, why would someone want to do this? It's not that mysterious. Someone thought it would be convenient to get the parent of a Finder item or the "storage" of an e-mail message, right? There are applications with analogous objects, but no way to get their parents. Suppose I get a collection of bookmarks from OmniWeb, and then I want to know the parent folder of a certain bookmark. I might do it like this:
--
tell app "OmniWeb"
get every bookmark of every bookmark of personal bookmarks
repeat with i in result
repeat with j in i
if name of j contains "Ed" then
try
j as string
on error eMsg
set head to (offset of " of <<" in eMsg) + 4
set tail to (offset of "application \"OmniWeb\"" in eMsg) + 20
return run script eMsg's texts from character head to tail
end
end
end
end
end
--> bookmark "Physical" of personal bookmarks of application "OmniWeb"
--
[Note that I used angle brackets instead of guillemets because I'm posting from .mac's web interface on a PC.]
Now, I could make a list of bookmarks folders and then compare the list to where I am in the collection of bookmarks, but I consider that to be more complex, conceptually. Programming is really hard, and every ounce of complexity you can sqeeze out is all to the better. I'd rather not think at the level of data types--lists, in this case--but instead at the higher level of the application metaphors--bookmarks and bookmark folders. "Hey, I've got a bookmark, who owns it?" If it takes a hack to get me there, I don't really care. If it comes up much, put it in a library.
That's not the only example; I've run into this issue several times.
Michael
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden