• 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
Drilling down into an AppleScript object reference
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Drilling down into an AppleScript object reference


  • Subject: Drilling down into an AppleScript object reference
  • From: "Scott Babcock" <email@hidden>
  • Date: Wed, 10 Aug 2005 15:14:52 -0700
  • Thread-topic: Drilling down into an AppleScript object reference

This may be old news to some of you, but I found that it's possible
through coercion to decompose an object reference to determine the
reference type [named/index/id], object class, selector, and container
object (the object's parent).

The process is fairly simple:

    tell application "System Event"
        tell application process "Finder"
            set objectRef to menu bar item 1 of menu bar 1
        end tell
    end tell

    set objRecord to (objectRef as record)
--> {<<class form>>:named, <<class want>>:menu bar item, <<class
seld>>:"Apple", from:menu bar 1 of application process "Finder"}

The biggest challenge is extracting the [from] property of the object
record, since AppleScript refuses to compile code with the word "from"
used as a property name. There are two workarounds:

1. Use the raw code <<class from>>, which will compile to the correct
Apple Event code and produce the desired result. The problem with this
is that you have to restore the raw-format code each time you need to
re-compile.
2. Coerce the object record to a list and get the property value from
that. This always seems to be the last item. If there are instances
where it isn't, it would be a process of elimination to figure out which
item in the list is the [from] property.

Using this technique, I can work around the AXParent bug in System
Events 1.2.1 and get the parent element of any arbitrary UI element.
This doesn't just work for System Events object references, though; it
works for objects of every application I tried.
 _______________________________________________
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: Split PDF and reduce file size
  • Next by Date: Re: Split PDF and reduce file size
  • Previous by thread: Re: Split PDF and reduce file size
  • Next by thread: POSIX and lists question
  • Index(es):
    • Date
    • Thread