Hi All,
I have this huge outline view that I want to be modified from time to time by the user not to mention possibly be modified entirely later on without modifying the code of my application, so I got the idea to storing the outline in a plist and just have it load up when the application launches.
Well I started to write my function to retrieve the outline and it seems when I loop through the first level of the plist it seems everything in proceduresOutline is out of order. Is it possible that the plist has no order? I know it has keys so I know that is quite possible, but the plist always saves in a particular order and it has item numbers.
Here is my code I use to retrieve my first level:
tell application "System Events"
tell property list file pListPath
tell contents
set itemCount to (count of property list items)
repeat with i from 1 to itemCount
set end of proceduresOutline to (name of item i of property list items)
end repeat
end tell
end tell
end tell
Does anybody have any experience storing and retrieving outlines from a plist?
Usually the data for an outline is in some sort of list format. As such here’s an example of how to read/write a list to a plist file. Note that a list is an NSArray in objective-c speak, so we can use the objective-c method of reading/writing an NSArray. If you’re outline data is in a record format then you could use the analogous NSDictionary methods for reading/writing it in the same manner.
In this example I have a list with 2 records in it, which you can see in the “will finish launching” subroutine.
property plistArray : null
property filePath : (path to desktop as text) & "test.plist"
on clicked theObject
set objname to name of theObject
if objname is "btnRead" then
set readPlist to call method "arrayWithContentsOfFile:" of class "NSArray" with parameter (POSIX path of filePath)
log readPlist
else if objname is "btnWrite" then
set r to call method "writeToFile:atomically:" of plistArray with parameters {POSIX path of filePath, true}
if r is 0 then
log "There was an error writing the file"
else if r is 1 then
log "The file was written correctly"
end if
end if
end clicked
on will finish launching theObject
set r1 to {theName:"name1", theAge:20}
set r2 to {theName:"name2", theAge:30}
set plistArray to {r1, r2}
end will finish launching