Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: XML - System Events vs XMLlib



On 2007-08-29, at 05:50:06, Wayne Melrose wrote:

I have a project where I'm forced to use System Events and not XMLLib.. Emmanuel, I knew you were going to say it.  :) . I use XMLlib for other projects, however, this one requires no installs on machines as the project leaders don't want it to involve any set up on the computers that will be running it.

sigh..

I had a look around last night for some sample code, and every time I looked it up it seemed to result in people suggesting XMLLib and not using System Events..

Getting to the point..
I tried to find some examples of System Events parsing a plist file.. Didn't get much..

Other people have asked here if there is any good suggestions for references, or sample code of System Event's parsing XML.. ??

There is SOME stuff out there, but it would be great to know if there is something as comprehensive as XMLlib out there for system events..

Do Apple have a plan for this? or are they just leaving it up to third party suppliers to do the work? Or have they done the work and I haven't found it?

Here's a sample of what I want..


--- the xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>keyname</key>
<integer>8</integer>
<key>creation</key>
<string>2007:06:12 20:13:52</string>
<key>happy</key>
</false>
</dict>
</plist>


How do I I search for "creation" and return the string value?

How to I search for "happy" and return "false"?

You won't be doing much with a document like the above. That's because the value for the key "happy" should be <false/>. And (minor point not terribly important) the document is not ordered the same as Property List Editor would order it.

The suite you want to use is the Property List Suite because the document type is 'plist'. Property Lists are only superficially XML. That's why there's a separate suite for them in AppleScript and separate APIs for them internally in both Carbon and Cocoa.


set f to "~/Desktop/some.plist"
set res to {}
tell application "System Events"
set plif to property list file f
set pitm to every property list item of plif
repeat with p in pitm
set end of res to {name, value} of p
end repeat
end tell
res

You can also use the 'defaults' tool in a 'do shell script'. Unless the plist file is located in ~/Library/Preferences, the path must be a full path without the ".plist" extension.

% defaults read ~/Desktop/some creation

Philip Aker
email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-users/email@hidden
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >XML - System Events vs XMLlib (From: Wayne Melrose <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.