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: Paul Berkowitz <email@hidden>
- Date: Tue, 07 Dec 2004 23:41:11 -0800
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:
>
> tell application "TextEdit"
> set objRef to a reference to word 12 of document 2
> end tell
>
> try
> {_:objRef} as text
> on error errmsg
> set head to (offset of ":" in errmsg) + 1
> set tail to (offset of "}" in errmsg) - 1
> set refStr to text from character head to character tail of errmsg
> end try
>
> 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:
tell application "TextEdit"
set objRef to a reference to word 12 of document 2
end tell
still produces the very same refStr:
--> "word 12 of document 2 of application \"TextEdit\""
evidently the canonical syntax. So I suppose you could continue
set AppleScript's text item delimiters to {" of "}
set bits to text items of refStr
set AppleScript's text item delimiters to {""}
bits
--> {"word 12", "document 2", "application \"TextEdit\""}
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?
--
Paul Berkowitz
_______________________________________________
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