I have a cocoa program that generates a plist file. I need to extract a list of numeric fileID’s from the plist, then I pass that list to Filemaker for further processing. I have that all working.
Here’s a sample of the plist:
<?xml version="1.0" encoding="UTF-8"?> <plist version="1.0"> <dict> <key>fileIDs</key> <array> <integer>10593</integer> <integer>10590</integer> <integer>10349</integer> <integer>3100</integer> </array> <key>name</key> <string>New Playlist</string>
Here’s how I am extracting the list:
set f to choose file with prompt "choose plist file" set thePListPath to POSIX path of f tell application "System Events" tell property list file thePListPath tell contents set myList to value of property list item "fileIDs" end tell end tell end tell
But there is a case where the above does not work, which is when the plist has nested lists, like this:
<?xml version="1.0" encoding="UTF-8"?> <plist version="1.0"> <dict> <key>fileIDs</key> <array> <integer>10593</integer> <integer>10590</integer> <integer>10349</integer> <integer>3100</integer> </array> <key>name</key> <string>New Playlist</string> <key>sublists</key> <array> <dict> <key>fileIDs</key> <array> <integer>10234</integer> <integer>10201</integer> <integer>10207</integer> <integer>10515</integer> </array> <key>name</key> <string>New Playlist2</string> </dict> </array> </dict> </plist>
In this case, my applescript gets the top array, but obviously fails to get the “sublists” array. Any advice on how to recurse through the sublists (there could be multiple levels) would be appreciated.
Thanks.
Jim Weisbin | C.T.O. | human | 138 Fifth Avenue | 3rd Floor | New York, NY | 10011 |
|