On 2006-10-01, at 06:23:57, Jaime Magiera wrote:
I'm working on a project that requires parsing a .plist file with plain vanilla AS. Though I've written a parser for server configuration files before, my knowledge of AS techniques is limited. Below is the text to parse...
[...]
The quoted array () could have any number of elements, which are also arrays, {}.
The {} delimiters enclose a plist dictionary.
I was thinking of doing this line by line, but it would be easier to break it up with text item delimiters. On the other hand, sending it to the command line via do shell script and running it through something else might work.
Anyone have suggestions for how to approach this? Thanks.
Looks like you're getting the text value from 'defaults read ...' because that's exactly what a plist array containing dictionaries looks like. So you'd be better off to read the plist directly with
the items in the Property List suite in System Events. Say the name of the array in the plist is "ServerAccounts". Then:
set f to ((path to desktop as string) & "test.plist")
set res to {}
tell application "System Events"
set plfile to property list file f
set plitem to value of property list item "ServerAccounts" of plfile
repeat with i in plitem
set end of res to i as list
end repeat
end tell
res
would give a result of something like:
{{"Adomain", "jmagiera", ".mac", "http://adomain.com", "www.adomain.com", "/Sites/podcast", "1158377199.667244"}, {"Adomain2", "jmagiera", ".mac", "http://www.adomain2.com", "idisk.mac.com", "/Sites/podcast", "1158373459.790697"}} Leave off the repeat loop to see what "value of property list item ..." gives if you need access to the keys.