Keilly: June 2007

Thursday, June 28, 2007

Speed up file writing

Simple writing to a file can be achieved by the following:

widget.system("/bin/echo name=" + value + " >> "
+ dataFileName, null);

New lines aren't allowed with this version of the echo command, so only one line can be written at a time. The problem is that system calls aren't very fast: who knows why, perhaps a new shell is created internally each call? Anyway, writing a file of more than a couple of lines is noticeably slow to the user. So we need a way to do this with less system calls.

'printf' does the job perfectly as it allows multiple line writing. Build up the string to write, separating lines with the '\n' character. Then write the whole file in one call....

var dataString = "";
for(i=0; i {
dataString += data[i].name + "=" + data[i].value + "\n";
}
if (dataString.length > 0)
widget.system("/usr/bin/printf '" + dataString +
"' > " + dataFileName, null);

So... much... faster...

Tuesday, June 12, 2007

Safari 3 Public Beta vs Dashcode Public Beta

I just installed the Safari 3 Public Beta, it's very nice but without AdBlock and to a lesser extent Greasemonkey it's never going to replace Firefox. Anyway, after firing up Dashcode Public Beta I noticed that there are rendering problems. Just creating a simple widget and resizing the front design is suddenly very problematic. I suppose Safari 3 has an updated version of Webkit that Dashcode Beta isn't ready for.

Uninstalling Safari 3 fixes things with Dashcode. A bit of a pity as Safari 3 was noticeably quicker that Safari 2 and much much faster than Firefox.

Incidentally, maybe a bonus reason for the release of Safari on Windows is to increase the number of plugins available. Plugins are certainly a big differentiator between Firefox and the other browsers, and while Safari is marginalized only on OSX it won't get the volume of [quality] plugins developed by 'the community' that Firefox does.

ZX Spectrum Widget in WWDC Keynote

While being embarrassed for a room full of grown men enthusiastically cheering and whooping at the announcement of a new 'Finder', I spotted that Steve Jobs was sharing the WWDC 2007 stage with a huge OSX feature that he somehow neglected to mention: My ZX Spectrum widget.
It's on around minute 45, blink very slowly and you'll miss it.

Saturday, June 2, 2007

Use the command line (to read/write files and other fun stuff)

Using the command line from a widget adds the ability to make widgets much more powerful than standard web pages. It's really easy to do by using the widget.system call.

e.g., to run a script (drag the script to your widget 'Files' section):
  widget.system("./myscript.sh", null);
Simple write to file 'data.txt'"
  widget.system("/bin/echo Some data >> data.txt", null);
widget.system("/bin/echo More data >> data.txt", null);
Simple file read from 'data.txt':
  var data =
widget.system("/bin/cat data.txt ", null).outputString;
Run a java application:
  widget.system("/usr/bin/java ", null)
Note the use of the path to the executable in the system call. Looks like the widget doesn't have a good path variable set up in it's shell. Not sure why, but it's easy enough to find an executable location by typing 'which java' in Terminal.

Make sure that the widget has the attribute 'Allow Command Line Access' turned on or instead you'll get a non obvious exception when executing the system call.