Re: How to work with XML data using System Events?
Re: How to work with XML data using System Events?
- Subject: Re: How to work with XML data using System Events?
- From: Paul Berkowitz <email@hidden>
- Date: Fri, 04 Nov 2005 11:08:13 -0800
- Thread-topic: How to work with XML data using System Events?
On 11/4/05 9:55 AM, "has" <email@hidden> wrote:
> But anyway, when working with plists it's simpler to use SE's dedicated PList
> Suite, e.g.:
System Events in OS 10.4.3 has both a "Property List Suite" (I assume that's
what you mean by "PList Suite") and an "XML Suite". Are these the same in
10.4.2? (It's a bit odd that you can't get 'property list item' out of any
property or element of 'property list file', and can't get 'XML data' out of
any property or element of 'XML file'. Is there some way to do it? Can you
just 'read' the file to get the equivalent of 'XML text' below, or is there
a lot of parsing to do to get rid of extraneous stuff?
And see below...
>
> -------
>
> tell application "System Profiler"
> set s to (XML text of document 1)
> end tell
>
> tell application "System Events"
> set plist to make new property list item with data s
> set hardwareRec to first property list item of plist where the value of its
> property list item "_dataType" is "SPHardwareDataType" -- [1]
> set itemsList to property list item "_items" of hardwareRec
> set overviewRec to first property list item of itemsList where the value of
> its property list item "_name" is "hardware_overview"
> return value of property list item "machine_name" of overviewRec
> end tell
>
> -------
>
> Unfortunately, the above code doesn't work when I tried it OMM (10.4.2) as the
> line marked '[1]' returns a reference to the wrong element. This appears to be
> a bug in System Events; don't know if it's fixed in 10.4.3, but if anyone can
> reproduce it there then they're welcome to file it.
It's still there. Since it's returning 'property list item 2 of property
list item "untitled"', instead of 'property list item 1 of property list
item "untitled"', which is the correct one, it looks to me as if there's
been an incorrect conversion of what was expected to be a 0-based list to a
1-based list whereas it was 1-based all along and didn't need converting. Or
something like that.
One could work around that until the bug is fixed ;-) :
tell application "System Events"
set plist to make new property list item with data s
set checkHardwareRec to first property list item of plist where the
value of its property list item "_dataType" is "SPHardwareDataType"
if the value of checkHardwareRec's property list item "_dataType" is
"SPHardwareDataType" then
set hardwareRec to checkHardwareRec
else
set checkHardwareRec to item 1 of (every property list item of
plist)
if the value of checkHardwareRec's property list item "_dataType" is
"SPHardwareDataType" then
set hardwareRec to checkHardwareRec
else
beep
display dialog "Use the other script, dammit!"
return
end if
end if
set itemsList to property list item "_items" of hardwareRec
set overviewRec to first property list item of itemsList where the value
of its property list item "_name" is "hardware_overview"
return value of property list item "machine_name" of overviewRec
end tell
--> "PowerMacG5"
--
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