• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Unwinding the containment hierarchy of a reference
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unwinding the containment hierarchy of a reference


  • Subject: Re: Unwinding the containment hierarchy of a reference
  • From: has <email@hidden>
  • Date: Wed, 8 Dec 2004 13:23:21 +0000

Michelle Steiner wrote:

 > There's just no built-in function to return, say, a list of objects
 > (e.g. {word 1 of paragraph 2 of document "foo", paragraph 2 of
 > document "foo", document "foo", application "TextEdit"})

There's where I'm failing to understand.  To get that list, either one
would need to parse the object specifier--but since the object
specifier is already known, why--or one would need to start somewhere
and work backwards.

An application reference is just a series records, called 'object specifiers', nested one inside another. Each of these records holds its parent reference in its 'from' property; other properties identify the property or element(s) being specified. This internal structure is hidden from AppleScript users, but it can easily manipulated via the Apple Event Manager API using a language that allows you to talk to the AEM directly, e.g. C, Perl, Python. For example, to build a list like:


{word 1 of paragraph 2 of document "foo", paragraph 2 of document "foo", document "foo"}

you'd use (pseudocode):

	set ref to reference to word 1 of paragraph 2 of document "foo"
	set result to {ref}
	repeat until ref is null:
		set ref to from of ref
		set end of result to ref


Breaking the reference right down:

{{"element", "word", {"index", 1}}, {"element", "paragraph", {"index", 2}, ...}

isn't much harder; e.g. it took me just a few minutes to write a Python module to do this.


BTW, I'm also curious why the OP wants to do this. It'd be easy to implement such a feature in appscript's application references, but I'd need to have a worthwhile reason for doing so.


has

p.s. If you really want to explore this stuff, I'd suggest using MacPython. The built-in Carbon.AE extension provides a basic wrapper around the AEM, and the aem and appscript packages (see my site) supply higher-level interfaces. It's all open-source and completely hackable, and a lot friendlier than working directly in C.
--
http://freespace.virgin.net/hamish.sanderson/
_______________________________________________
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
  • Prev by Date: Re: swf movie
  • Next by Date: AppleScript to remove a folder action
  • Previous by thread: Re: Unwinding the containment hierarchy of a reference
  • Next by thread: Re: Unwinding the containment hierarchy of a reference
  • Index(es):
    • Date
    • Thread