Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Reading into plist files

Hi,

I'm building an app that relies heavily on reading plist files. I've got the basics down using System Events, for example:

tell application "System Events"
set plistFile to "/Library/Preferences/com.domain.prefs.plist"
set returnVal to (value of property list item "MyValue" of property list file plistFile)
display dialog returnVal
end tell

To extract from the following plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>MyValue</key>
<string>1000</string>
</dict>
</plist>

But of course I need to read further into plist files, count the number of re-occurrences of certain items and so on. For example, if I wanted to read into the following plist file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>MyValue</key>
<key>ArrayInfo</key>
<array>
<dict>
<key>Bool</key>
<true/>
<key>Value1</key>
<string>1000</string>>
</dict>
<dict>
<key>Bool</key>
<true/>
<key>Value1</key>
<string>4000</string>>
</dict>
</array>
</dict>
</plist>

How can I extract, for example, the number of records within the array and then create an AS list of each re-occurrence of 'Value1' or 'bool'?

Any help on this or any links to good tutorials will be much appreciated.

Many thanks.

MacBook Pro, Mac OS X (10.5.6)

Posted on Jan 15, 2009 12:58 PM

Reply
2 replies

Jan 15, 2009 2:12 PM in response to Rob Riley1

If you read a property list item that is an array you get a list of items returned to your script. From there you can iterate through your items as required.

For example, in your .plist, you'd have to fetch property list item "ArrayInfo"

From there you'd get a list with two items, so you'd have to iterate through that:

repeat with eachArrayItem in property list item "ArrayInfo"


Now you have each item in the array and can query the low level values.

Reading into plist files

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.