Widget.System Limitations
iaian7 » blog John Einselen, 26.09.09Development of the Chroma dashboard widget has been moving along nicely, but I hit a pretty catastrophic error today; the library file was getting truncated. A lot of changes have been made recently to the formatting of the data, so the most plausible culprit was myself. Surely, somewhere in the reading, modifying, and writing back to the library file via command line interface, I’d screwed something up.
After 4 hours trying innumerable possibilities, hacks, tests, and workarounds (all of them failed), I discovered it wasn’t me at all; my macbook was limiting the outputString
from widget.system
to 4096 bytes. What truly makes this bizarre is that the Mac Pro at work does not have this same limitation, and they’re both Intel 64bit processors running the same version of OS X. I still don’t know how this is even happening; most online sources claim running widget.system asynchronously removes the limits. Well, I now have plenty of proof that says otherwise!
The good news? I finally worked out a solution. Using the myCommand.onreadoutput function, I was able to add each block of 4096 bytes back into a full length javascript string. Perhaps not the most elegant solution, but should work across all systems.
var libString = ""; var commandString = "cat /directory/file.txt"; function getLibrary(event) { var myCommand = widget.system(commandString, processLibrary); myCommand.onreadoutput = processLibraryConcat; } function processLibraryConcat(event) { libString = libString+event; } function processLibrary(event) { // library processing should use libString (full length output) // instead of event.outputString (truncated to 4096 bytes) }