| Sign In/My Account | View Cart |
| Article: |
Build a Dashboard Widget | |
| Subject: | It doesn't work | |
| Date: | 2005-06-14 11:33:30 | |
| From: | TimGrant | |
|
Response to: It doesn't work
|
||
|
What you're describing happened to me too. I made some changes to the JavaScript and now it works a little bit better:
|
||
Showing messages 1 through 2 of 2.
widget.system. By specifying a handler, you're changing from synchronous operation to asynchronous operation.var output = widget.system(commandLine, null);
document.getElementById('outputArea').value = output.outputString;
widget.system() is performed synchronously and thus makes the Widget wait for the output from the call to complete before continuing its own execution. Unfortunately, when this method is called synchronously (that is, when its second argument is null), one needs to specify a property of the method to capture, as explained in the Dashboard Programming Guide in the section on Command-Line Access, under Synchronous Operation.widget.system(commandLine, null) as shown above executes the comman, but any output is lost since you dont specify that you want that information. To get its output, specify the outputString property and save it in a variable:var output = widget.system(/usr/bin/id -un, null).outputString;var output = widget.system(commandLine, null).outputString;
document.getElementById('outputArea').value = output;
Info.plist file is required to have a CFBundleDisplayName key as well as a CFBundleVersion key, but is not required to have a Width or a Height.
if (document.getElementById('programName').value != null) {
var commandLine =
'groff -mandoc -Tascii -P-b -P-c `/usr/bin/man -w "'
+ document.getElementById('programName').value+'"`'
+ ' | head -366 | /bin/cat';
var output = widget.system(commandLine, null);
document.getElementById('outputArea').value = output.outputString;
}