Women in Technology

Hear us Roar



Article:
  Build a Dashboard Widget
Subject:   It doesn't work
Date:   2005-05-06 18:16:36
From:   kevincranford
I must be doing something wrong because I copied and pasted eveything in this article and I cannot get it to work.
Full Threads Oldest First

Showing messages 1 through 9 of 9.

  • It doesn't work
    2005-06-14 11:33:30  TimGrant [View]

    What you're describing happened to me too. I made some changes to the JavaScript and now it works a little bit better:

    function getManPage()
    {
    if (document.getElementById('programName').value != null)
    {
    var commandLine = 'groff -mandoc -Tascii -P-b -P-c `/usr/bin/man -w "' + document.getElementById('programName').value+'"`' + ' | col -b '
    document.getElementById('outputArea').value = "Processing..."
    var output = widget.system(commandLine, myEventHandler);
    }
    }

    function myEventHandler(cmd)
    {
    document.getElementById('outputArea').value=cmd.outputString;
    cmd.close
    }

    It still only works on some terms, though, e.g., "chown" but not "chmod".
    • It doesn't work
      2007-03-23 20:01:10  jeffclough [View]

      Some trial and error shows that the output control can only hold up to 366 lines of text. This seems like an odd number, so maybe it's different from system to system (or version to version or whatever). I just used the head command to truncate the output:


      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;
      }
    • The Working JavaScript Function and Explanation of Error in Article
      2005-06-30 00:59:51  maymay [View]

      The reason the above code doesn't work (at least not on 10.4.1) is because the Widget will freeze, waiting for output, due to the call from widget.system. By specifying a handler, you're changing from synchronous operation to asynchronous operation.

      These are the offending lines that need to change in the article:
      var output = widget.system(commandLine, null);
      document.getElementById('outputArea').value = output.outputString;


      What's happening here is that the call to 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.

      As cited in the Guide: Running widget.system(commandLine, null) as shown above executes the comman, but any output is lost since you don’t 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;


      So learning from this example, the getManPage() JavaScript function's lines mentioned above should be changed to this and it will work:

      var output = widget.system(commandLine, null).outputString;
      document.getElementById('outputArea').value = output;


      Additionally, it should be noted that according to Apple's introduction to developing a Dashboard widget, the 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.

      Best regards, and best of luck,
      -Meitar Moscovitz
      http://www.maymay.net/ (Personal site)
  • It doesn't work
    2005-05-07 05:18:46  Andrew Anderson | [View]

    Hi.
    What does not work for you ?

    When you load Dashboard does it load in the window ?
    or
    Does the functionality not work when you try to run it ?

    The first one is probably XML driven, the second HTML driven.

    One way to debug Widgets, is to actually use the "Console" application, in the Applicatiosn/Utilities folder. All Javascript errors/messages will go here. Load that up and it should give you a pointer to any problems.
    • It doesn't work
      2005-05-23 11:14:49  andyinindy [View]

      Here's one that works great; maybe we can figure out how he did it!

      http://www.interdimensionmedia.com/downloads/NIXmanual.zip
      • re:It doesn't work
        2005-05-23 16:11:43  Andrew Anderson | [View]

        AndyInIndy,
        Thanks for the post. I looked at the widget briefly and it looks like they have some complex javascript doing the work. I will take a closer look and post something if I can get it together better.

        thanks again,
        Andrew
    • ...doesn't work...
      2005-05-11 09:18:20  andyinindy [View]

      Same here; the widget freezes, no man page displayed, no helpful output in console.

      I am convinced that widget.system is hopelessly broken. Maybe 10.4.1 will fix it. Here's someone who also hates widget.system:

      http://www.mikeash.com/blog/pivot/entry.php?id=6
      • ...doesn't work...
        2005-05-11 10:58:08  Andrew Anderson | [View]

        it definately behaves differently between the pre-release versions of Tiger and the final release build.

        what was most frustrating when I was debugging the problem in the release build is that Dashboard would crash, wouldn't pick up new versions of the Widget as they were created and just suffered from general weird behavoir.

        the only thing that even approximates a debug environment is the mix of the console and using javascript alert statements, which is not an easy way to debug anything.

        I confirmed that the latest version of the code, works in the release build of Tiger, but as you said widget.system seems to be hopeless broken.

        Thanks for the feedback though, I think part two of the article will focus more on how to setup some semblance of a development/debug environment and using the other features of Dashboard.
    • It doesn't work
      2005-05-07 16:26:30  kevincranford [View]

      The Dashboard Widget loads but when I enter something to get the man page on (like ls) it just sits there and shows nothing. It also wouldn't let me enter anything else into the search field. I checked the console and there is nothing related to this logged there either.