• 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: Accessing Child Elements of Property List Records or Lists
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accessing Child Elements of Property List Records or Lists


  • Subject: Re: Accessing Child Elements of Property List Records or Lists
  • From: Grant Erickson <email@hidden>
  • Date: Sun, 16 Aug 2009 13:33:37 -0700
  • Organization: Nuovation System Designs, LLC
  • Thread-topic: Accessing Child Elements of Property List Records or Lists

On 8/15/09 5:51 PM, red_menace wrote:
> On Aug 15, 2009, at 1:00 PM, Grant Erickson wrote:
>> I am attempting to use the Property List Suite of the System Events
>> dictionary to customize window views using a property list of attributes for
>> those customizations (bounds, view style, view options, etc.).
>>
>> I seem to be able to successfully access all the top-level items from the
>> property list using:
>>
>>     on GetObjectForKeyInFile(inFile, inKey)
>>         tell application "System Events"
>>             tell property list file inFile
>>                 tell contents
>>                     return value of property list item inKey
>>                 end tell
>>             end tell
>>         end tell
>>     end GetObjectForKeyInFile
>>
>> with examples such as:
>>
>>     set theBoolean to my GetObjectForKeyInFile(thePlist, "Tool Bar")
>>
>>     if theBoolean is not {} then
>>             set toolbar visible to theBoolean
>>     end if
>>
>> However, when retrieve a dictionary (record) and then get a child of them
>> it:
>>
>>     on GetObjectForKeyInRecord(inRecord, inKey)
>>         tell application "System Events"
>>             tell property list item inRecord
>>                 return value of property list item inKey
>>             end tell
>>         end tell
>>     end GetObjectForKeyInRecord
>>
>> with an example such as:
>>
>>     set theBounds to my GetObjectForKeyInFile(thePlist, "Bounds")
>>     set theHeight to my GetObjectForKeyInRecord(theBounds, "Height")
>>
>> I get an error of:
>>
>>     System Events got an error: Can¹t get property list item {|X|:10,
>> |Y|:10, |Width|:480, |Height|:320}. Invalid index. (-1719)
>>
>> Any insights? I am certain there is some "of..." or "as..." syntax I am
>> missing here; however, various combinations of "as record", etc. have proved
>> fruitless.
>
> Each property list item can also contain other property list items.  In your
> example,
> you are using the value of one property list item (a record) as the key for
> getting
> another property list item.  You just need to break down each key/subitem - I
> use
> a list of items to build a reference to the desired property list element:
>
> to GetPlistElement from PlistItems
>
> For your example, the usage would be  my (GetPlistElement from {thePlist,
> "Bounds", "Height"})

Dave:

Thanks for the insight and prompt reply. It would appear, in my case, that I
was simply making things more complicated than necessary. Once I get a
top-level item from GetObjectForKeyInFile, I can simply treat them as the
list or record composition that they are and access them that way:

    set theBounds to my GetObjectForKeyInFile(thePlist, "Bounds")
    set theHeight to |Height| of theBounds
    set theWidth to |Width| of theBounds

or:

    set theItems to my GetObjectForKeyInFile(thePlist, "Items")

    repeat with theItem in theItems
        local theName, thePosition

        set theName to |Name| of theItem
        set thePosition to |Position| of theItem

        try
            set position of item theName to {|X| of thePosition, |Y| of
thePosition}
        end try
    end repeat

Thanks again,

Grant


 _______________________________________________
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

  • Follow-Ups:
    • Re: Accessing Child Elements of Property List Records or Lists
      • From: "Mark J. Reed" <email@hidden>
References: 
 >Re: Accessing Child Elements of Property List Records or Lists (From: red_menace <email@hidden>)

  • Prev by Date: Re: iCal events to a list
  • Next by Date: Re: Accessing Child Elements of Property List Records or Lists
  • Previous by thread: Re: Accessing Child Elements of Property List Records or Lists
  • Next by thread: Re: Accessing Child Elements of Property List Records or Lists
  • Index(es):
    • Date
    • Thread