3 Replies Latest reply: Oct 25, 2006 9:22 AM by jbarros
jbarros Level 1 Level 1 (20 points)
Hello,

I have need to have a script I'm writing edit .plist files. Is there an RFC somewhere that covers the markup of .plists? anyone want to point me at what I should do to write one of these myself in plaintext?

Thanks.

-- James

   
  • Michel Lemieux Level 2 Level 2 (230 points)
    Hi James,

    HAve a look at Late Night Software's "Property List Tool" (http://www.latenightsw.com/freeware/PListTools/index.html). It is very easy to use and quite reliable, with no or minimal learning curve.

    Hope this helps!
  • Steve Herman1 Level 4 Level 4 (2,545 points)
    James,

    Property list files are a specific type of XML document although in Tiger they are often stored in a binary format. You may want to look at Apple's Property List Programming Guide or Apple's DTD (Document Type Definition) for property lists (if you understand how to read a DTD).

    The "defaults" command line tool can be used to read/write plist files as long as you don't have to deal with complex nested structures. So it may be useful in your script.

    There's also a command line utility that comes embedded inside some of Apple's installers called PlistBuddy. You probably have some copies of this utility inside some of the installer receipts left behind in your /Library/Receipts folder. Executing PlistBuddy with a "-h" option will print out some usage information. For example:
    <pre>
    /Library/Receipts/SomePackageName.pkg/Contents/Resources/PlistBuddy -h
    </pre>
    The defaults command can access a property list file either as an XML text file or as a binary file... I'm not sure about PlistBuddy as I've never had a reason to use it.

    If you have installed the Xcode Tools you'll also have Property List Editor (in /Developer/Applications/Utilities). Property List Editor is a GUI app that you can use to read/write plist files. It may be useful if you need to tinker with a plist file interactively, but it's probably not much use for scripting.

    You can also use the "plutil" command line tool, if needed, which allows you to convert a binary plist file into an XML text file. You can then manipulate the text file with other text processing tools and use plutil again to convert back to binary.

    If you need to work with complex or deeply nested data within the plist file then the defaults command may not be capable of doing it. You could potentially write a Cocoa tool that makes use of an NSDictionary/NSMutableDictionary to manipulate the plist data. The NSDictionary class in Cocoa makes it very easy to read/write a property list file with a single line of code. Once you've read the plist file into an NSDictionary you can use all the various class/instance methods to manipulate the dictionaries structure and data.

    Steve
  • jbarros Level 1 Level 1 (20 points)
    Thank you, that could have worked for me. I should have specified that I'm doing this in php not applescript. I know I could dynamicly generate applescript and have it call that, but I'd prefer to avoid the extra step.

    -- James