Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: widget.system - can't get it to work.



Chris—

On Jun 25, 2005, at 9:10 PM, chris bernick wrote:

Hello,

Is there anyone who could help me with this problem?
I simply cannot get widget.system to work in it's
simplest form.  I have the following javascript:

    document.getElementById("out").value = "hello";
    document.getElementById("out").value =
widget.system("/usr/bin/id -un", null).outputString;
    //document.getElementById("out").value = "world";

...and the following in info.plist:

    <key>AllowSystem</key>
    <true/>

"hello" is displayed in the text field just fine, but
the 2nd line doesn't work.  If the 3rd line is
uncommented, it "world" is NOT displayed indicating
that the script is crashing on the 2nd line.  What am
I missing here?

There's a couple of things that could be going wrong here. The good news is that your widget.system call is fine—the problem may lie with what you're doing with the results. The .value property works if you're working with an input (i.e. text field), but if you're dealing with a text element wrapped in a div or span, you're going to want to use the .innerText value:


document.getElementById("out").innerText = widget.system("/usr/bin/id -un", null).outputString;

More importantly, make sure that "out" is an id attribute on the element you're assigning it to—"class" attributes aren't modifiable via JavaScript.

Finally, make sure the code is called after the widget's structure is loaded—having it inline causes it to be called before the DOM structures exist.

Here's a modified version of the Hello World sample widget that works (with AllowSystem enabled, of course):

<html>
<head>
<style>
body {
    margin: 0;
}

#helloText {
font: 24px "Lucida Grande";
font-weight: bold;
color: white;
text-align: center;
position: absolute;
top: 41px;
left: 30px;
width: 156px;
}
</style>
<script>
function loaded()
{
document.getElementById("helloText").innerText = "hello";
if(window.widget) {
document.getElementById("helloText").innerText = widget.system("/usr/bin/id -un", null).outputString;
}
//document.getElementById("out").value = "world"
}
</script>
</head>
<body onload="loaded();">
<img src="Default.png">
<div id="helloText">Hello, World!</div>
</body>
</html> _______________________________________________
Do not post admin requests to the list. They will be ignored.
Dashboard-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/dashboard-dev/email@hidden


This email sent to email@hidden
References: 
 >widget.system - can't get it to work. (From: chris bernick <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.