Each widget must have an information property list file associated with it. This file provides Dashboard with information about your widget. Dashboard uses this information to set up a space in which it can operate.
The Info.plist file contains the needed information. In a basic widget’s information property list file are five mandatory values and four optional values. The properties are listed in Table 2-2, along with a definition and the value used in the sample Hello World widget:
Property | Example | Definition |
|---|---|---|
|
| Required. A string that uniquely identifies the widget, in reverse domain format. |
|
| Required. A string that provides the name of your widget. Must match the name of the widget bundle on disk, minus the |
|
| Required. A string that reflects the actual name of the widget, to be displayed in the widget bar and the Finder. |
|
| Required. A string that gives the version number of the widget. |
|
| Optional. An integer between 0 and 100 that sets the placement of the widget’s close box on the x-axis. |
|
| Optional. An integer between 0 and 100 that sets the placement of the widget’s close box on the y-axis. |
|
| Optional. A number that gives the height, in pixels, of your widget. If not specified, the height of Default.png is used. |
|
| Required. A string that gives the name of the main HTML file that implements your widget. |
|
| Optional. A number that gives the width, in pixels, of your widget. If not specified, the width of |
Of note are the CloseBoxInsetX and CloseBoxInsetY values. These values determine the placement of the close box over the top-left corner of your widget. You should position the close box so that the "X" is centered over the top-left corner of the widget.
The complete information property list file for the Hello World sample widget looks 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>CFBundleDisplayName</key> |
<string>Hello World</string> |
<key>CFBundleIdentifier</key> |
<string>com.apple.widget.helloworld</string> |
<key>CFBundleName</key> |
<string>Hello World</string> |
<key>CFBundleShortVersionString</key> |
<string>1.0</string> |
<key>CFBundleVersion</key> |
<string>1.0</string> |
<key>CloseBoxInsetX</key> |
<integer>16</integer> |
<key>CloseBoxInsetY</key> |
<integer>14</integer> |
<key>MainHTML</key> |
<string>HelloWorld.html</string> |
</dict> |
</plist> |
Note that in this Info.plist, the Width and Height keys are omitted. As previously mentioned, these keys are optional. Since they aren’t included, the widget is automatically sized based on the dimensions of its default image.
There are more, optional Info.plist keys than those used here; read about them in Dashboard Reference. Of particular note are the Access Keys, which allow you to turn on access to external resources. Specifying Access Keys discusses these more in-depth.
Note: While an Info.plist file is just a text file, it's easiest to edit one using the Property List Editor application. It's found in /Developer/Applications/Utilities/ on your hard disk after you installed the Xcode Tools.
Last updated: 2006-01-10