PlistEdit Pro Icon

Property list definition example

For an example of property list definitions in action, open up the Info.plist file in TextEdit's bundle and the Info.plist plist definition file. (Open these files for me)

Bring the InfoPlist.plistDefinition window to the front and open up the DefinitionElements key of the root dictionary. Next, open up the <Root> key of that dictionary. This <Root>dictionary defines what the root of an Info.plist file should look like.

Figure 1: The definition element for the root dictionary in an Info.plist file

It declares that the root should be a dictionary, and defines a large list of types for various keys that can be found in Info.plist files. For example, under DictionaryKeyTypes, it declares that the CFBundleDisplayName key should be a simple String value. Further down, it declares that the CFBundleDocumentTypes key should be of type Array<DocumentTypeDictionary>. This means that the CFBundleDocumentsTypes value should be an array, each of whose children is a DocumentTypeDictionary.


Figure 2: The definition element for the children of the CFBundleDocumentTypes key

Now, go over to TextEdit's Info.plist file. Go to the Definitions menu and select Change Definition->Info.plist. This will tell PlistEdit Pro to interpret the Info.plist file using the plist definition we were just looking at. A new column titled "Element" should appear (if it doesn't, go to the Definitions tab in the preferences window and check the box labelled "Show column for definition element identifiers"). This column shows the name of the definition element currently associated with each object in the property list.


Figure 3: TextEdit's Info.plist file, as interpreted by the property list definition

You can see that the root object is, of course, associated with <Root>. A couple rows down, the CFBundleDisplayName key is associated with the basic element type "String". Notice that the pop-up in the Class column is grayed out, since String is the only valid type for this key. The CFBundleDocumentTypes is a Array<DocumentTypeDictionary> element, so each of its children is a DocumentTypeDictionary element.

In the first document type dictionary, you can see how each key's type is defined by the property list definition. The CFBundleRoleType key has only a handful of valid values, so those values are available to choose from in a pop-up menu in that row. The LSIsAppleDefaultType key is not officially defined as an Info.plist key, so it has no element type and can be edited without restriction.

Default values

One of the advantages of using property list definitions is that it allows PlistEdit Pro to fill in commonly used default values for new items that are created in the property list. Select the CFBundleDocumentTypes dictionary in the Info.plist file and select "New Child" from the Operations menu. PlistEdit Pro creates a new child, which is assigned a type of DocumentTypeDictionary just like all the existing document types. If you expand the newly created child, you'll see that it has already populated the new dictionary with several values. These values are obtained from the DefaultValue key in the definition element dictionary for the DocumentTypeDictionary element. PlistEdit Pro automatically inserts these default values to save you having to type in the same keys over and over by hand. If you wish to set a default value for an existing item, select "Set Default Value" from the Definitions menu.

Dictionary previews

When looking through a list of dictionaries, it can be difficult to find the one you want, since you have to expand each one to look at its contents. A "preview key" can be specified for a dictionary definition element, and the value of that key will be displayed in the value column for the dictionary itself. In the Info.plist above, "CFBundleName" is specified as the preview key for DocumentTypeDictionary elements, allowing you to easily determine which dictionary is which without having to expand each one.

Adding keys

When using a plist definition, PlistEdit Pro also provide an easy way to add keys that are defined in the plist definition but not yet added to the property list. Select the root item in the Info.plist, then go to the Definitions menu and look in the "Add Child Key" submenu. Here, you'll see listed all the child keys that are defined for the root dictionary but which aren't present in the Info.plist. If you select one of these items, it will create that key in the dictionary and assign it a default value. Similarly, the "Add Sibling Key" will provide choices for adding a sibling of the currently selected item.

See also:

Property List Definitions

Property List Definition Specification