Recent Widgets


Register for DashboardWidgets

Recent Forums Posts

Partners


iCompositions

MacDesktops.net

RSS Showcase
RSS Comments
RSS Forums

This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies. Posted in: Widget Development

widget.system help - .outputString not working

Author Message
funkdaddy



Joined: 25 Apr 2005
Posts: 35

Posted: Wed May 04, 2005 - 9:22 pm    Post subject: widget.system help - .outputString not working Reply with quote

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test</title>
<script type="text/javascript">

   function done() {
      document.getElementById('outputText').innerHTML = "Current path is: " + test.outputString;
   }
   
   function setup() {
      var test = widget.system("/bin/pwd", done);
   }
</script>
</head>
   
<body bgcolor="white" onload="setup();">
   <div id="front">
      <div id="outputText"></div>
   </div>
</body>
</html>


Can anyone tell me why the test.outputString doesn't return anything and hangs the widget? If I remove the "test.outputString" from the string it return the plain text just fine. Thanks.
View user's profile Send private message Send e-mail Widgets
Chris



Joined: 27 Jan 2005
Posts: 344
Location: Durham, UK

Posted: Thu May 05, 2005 - 2:29 am    Post subject: Reply with quote

Try making test a global variable. At the moment it's only within the scope of the function setup().

To be honest, you'd be just as well doing that synchronously.

Code:

function getPWD() {
     var test = widget.system("/bin/pwd", null);
     document.getElementById('outputText').innerHTML = "Current path is: " + test.outputString;
}
View user's profile Send private message Send e-mail Visit poster's website AIM Address Widgets
funkdaddy



Joined: 25 Apr 2005
Posts: 35

Posted: Thu May 05, 2005 - 8:56 am    Post subject: Reply with quote

well pwd was a bad example I was using that as a test. I'm really using 'curl > file.txt" to grab some info, then set the status to keep the user informed, it can take some time to process, so I'm using it asynchronously. But when I call the .ouitputString, I get nothing. Am I using the ouputString or widget.system wrong? It should process the function in the second half of hte quotes after it completed and you can use outputstring to get information returned?
View user's profile Send private message Send e-mail Widgets
kps



Joined: 03 May 2005
Posts: 10
Location: Waterloo, ON, Canada

Posted: Thu May 05, 2005 - 10:18 am    Post subject: Reply with quote

What Chris was trying to point out is that when you write this:
Code:
function setup() {
  var test = widget.system("/bin/pwd", done);
}

the var declaration makes test a local variable -- it can only be "seen" inside setup().

So -- if you actually have to do it this way -- you could try making test a global variable or a document property, e.g.
Code:
function done() {
  document.getElementById('outputText').innerHTML =
      "Current path is: " + document.test.outputString;
}
   
function setup() {
  document.test = widget.system("/bin/pwd", done);
}

or, write the callback inside setup() where it can see test, e.g.
Code:
function setup() {
  var test = widget.system("/bin/pwd", function () {
      document.getElementById('outputText').innerHTML =
          "Current path is: " + test.outputString;
    });
}


But, according to the Dashboard Programming Guide (I don't have Tiger to actually test this), the end callback receives the widget.system() result as an argument, so you probably just want
Code:
function done(x) {
  document.getElementById('outputText').innerHTML =
      "Current path is: " + x.outputString;
}

function setup() {
  var test = widget.system("/bin/pwd", done);
}

or more concisely
Code:
function setup() {
  widget.system("/bin/pwd", function (x) {
      document.getElementById('outputText').innerHTML =
          "Current path is: " + x.outputString;
    });
}
View user's profile Send private message Send e-mail Visit poster's website Widgets
funkdaddy



Joined: 25 Apr 2005
Posts: 35

Posted: Thu May 05, 2005 - 4:57 pm    Post subject: Reply with quote

Thanks that helped a lot!
View user's profile Send private message Send e-mail Widgets
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.

 
Powered by phpBB © 2001, 2002 phpBB Group