Read/Write Property Lists

Prior to Mac OS X v10.5, property lists could only be read using the related suites in the System Events application. In Leopard, property list files can be created and edited. Here's a script example of how to create and populate a property list file:

Click to open example in the Script Editor applicationAn example script demonstrating how to create an new property list file:
 

tell application "System Events"
 -- create an empty property list dictionary item
 set the parent_dictionary to make new property list item with properties {kind:record}
 -- create new property list file using the empty dictionary list item as contents
 set the plistfile_path to "~/Desktop/example.plist"
 set this_plistfile to ¬
 make new property list file with properties {contents:parent_dictionary, name:plistfile_path}
 -- add new property list items of each of the supported types
 make new property list item at end of property list items of contents of this_plistfile ¬
 with properties {kind:boolean, name:"booleanKey", value:true}
 make new property list item at end of property list items of contents of this_plistfile ¬
 with properties {kind:date, name:"dateKey", value:current date}
 make new property list item at end of property list items of contents of this_plistfile ¬
 with properties {kind:list, name:"listKey"}
 make new property list item at end of property list items of contents of this_plistfile ¬
 with properties {kind:number, name:"numberKey", value:5}
 make new property list item at end of property list items of contents of this_plistfile ¬
 with properties {kind:record, name:"recordKey"}
 make new property list item at end of property list items of contents of this_plistfile ¬
 with properties {kind:string, name:"stringKey", value:"string value"}
end tell

The resulting XML of the newly created property list will look something like this:

<?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>booleanKey</key>
<true/>
<key>dateKey</key>
<date>2007-08-07T22:09:04Z</date>
<key>listKey</key>
<array/>
<key>numberKey</key>
<integer>5</integer>
<key>recordKey</key>
<dict/>
<key>stringKey</key>
<string>string value</string>
</dict>
</plist>