It was more out of necessity than anything else, but since I had to port iRank to OSX, I figured I might as well give these "widgets" a try, since the dashboard seems like a pretty suitable place to put iRank.
I've finally got it working, thankfully. It's got some weird bugs (and you have to edit the source to customise it), so call it a beta ;)
Here are some observations on the process.
- Talking to iTunes is done by calling widget.system, and passing the name of an applescript (and some variables) to
/usr/bin/osascript, which then executes the applescript. This seems very inefficient to me, but it's done infrequently so it's not a big deal. - iTunes won't send events. I don't think you can catch events with a widget, but even if you write a fully-fledged program you can't get notified of iTunes events - you just have to poll it every n seconds. Apparently there is a framework in place for inter-application messages, but iTunes doesn't expose any events...
- Debugging is not much fun. You can use safari (after using this trick to enable developer features like a JavaScript console), but then you can't use the widget object (to do stuff a regular webpage can't). And you can keep switching to dashboard and reloading it, but it's very difficult to debug code when you have no error logging or alert().
- The use of JSON: I tried constructing objects as JSON instead of using tedious calls to document.createElement() and element.setAttribute(), which works nicely for simple data structures. But if you construct a HTML fragment with this method and then try and insert it into the DOM, you get a wonderfully usless error message: "DOM Exception 8". I still have no idea what this error means (googling revealed nothing), so I just ended up doing things the tedious way.
- Using Preferences looks like hard work :/
I ought to set this up at some stage, but for the moment I don't think anybody else uses it, and you only really need to set the preferences once...
If you're happy to change settings by editing an array in a javascript file, go ahead and give it a try (settings are on the first line of iRank.js).




