The following sections describe the methods of the Widget object.
openApplication
openURL
preferenceForKey
prepareForTransition
performTransition
setCloseBoxOffset
setPreferenceForKey
system
Launches the application with the specified bundle identifier.
widget.openApplication(bundleId) |
Use this method to launch the application indicated by bundleId on the target system. Calling this method dismisses the Dashboard layer.
Opens the specified URL in the user’s preferred browser.
widget.openURL(url) |
This method opens the specified URL and dismisses the Dashboard layer. This method does not permit the opening of URLs that use the file: scheme unless the AllowFileAccessOutsideOfWidget key is set in the widget’s information property list file.
Returns the preference associated with the specified key.
widget.preferenceForKey(key) |
Use this method to retrieve a preference value previously stored with a call to setPreferenceForKey. The method returns a string with the contents of the preference, or undefined if no such preference exists.
Notifies Dashboard that you are about to perform a transition to or from its reverse side.
widget.prepareForTransition(transition) |
This method prepares your widget for either showing or hiding its reverse side.
Passing the string “ToFront” for transition disables screen updates within your widget’s user interface so that you can prepare it for displaying your widget’s reverse side. Passing the string “ToBack” for transition freezes your widget’s user interface so that you can prepare it for displaying the main contents again. When your HTML layers are ready, call performTransition to display them.
Runs an animation to toggle between your widget’s reverse and contents.
widget.performTransition() |
You call this method after first calling prepareForTransition, which indicates whether you are displaying your widget’s reverse side or contents. When you call performTransition, Dashboard begins an animation that makes the widget appear to flip over and display the new content.
Prior to calling this method, you should also adjust the style sheet properties of your HTML to reflect the change in what is about to be displayed. For example, before calling this method to show your reverse side, you should show the HTML elements associated with your reverse side and hide those elements associated with your widget’s contents.
Changes the location of the widget close box.
widget.setCloseBoxOffset(x, y) |
Use this method to move your widget’s close box. This method centers the close box x pixels from the left edge of the widget and y pixels down from the top of the widget. Only values between 0 and 100 are allowed for x and y.
Associates a preference with the given key.
widget.setPreferenceForKey(preference, key) |
The preference and key parameters contain strings representing the preference you want to store and the key with which you want to associate it. Specifying null for the preference parameter removes the specified key from the preferences.
Preferences saved using setPreferenceForKey are saved as clear text and therefore are not recommended for saving passwords or other sensitive information.
Executes a command-line utility.
widget.system(command, endHandler) |
The command parameter is a string that specifies a command utility to be executed. It should specify a full or relative path to the command-line utility and include any arguments. For example:
widget.system("/usr/bin/id -un", null); |
The endHandler parameter specifies a handler to be called when the command has finished executing. If NULL, the entire method is run synchronously, meaning that all execution inside the widget halts until the command is finished. When running synchronously, these options are available:
Property | Definition | Usage |
|---|---|---|
| The output of the command, as placed on |
|
| The output of the command, as placed on |
|
| The exit status of the command. |
|
If endHandler is specified, the command is run asynchronously, meaning that the command runs concurrently and the handler is called when execution is finished. When run asynchronously, widget.system returns an object that can be saved and used to perform other operations upon the command:
Option | Purpose | Description |
|---|---|---|
| Property | The current string written to |
| Property | The current string written to |
| Property | The command’s exit status, as defined by the command. |
| Event Handler | A function called whenever the command writes to |
| Event Handler | A function called whenever the command writes to |
| Method | Cancels the execution of the command. |
| Method | Writes a string to |
| Method | Closes |
Note: To use widget.system, you need to set the AllowSystem key in your Info.plist. For more information, see “Dashboard Info.plist Keys.”
Last updated: 2006-05-23