Working with AmazonHandler

As I promised a few weeks ago, I’ve spent a little more time working on AmazonHandler. The biggest problems people have had with it are that

  1. it requires a supporting script which has to be loaded from a fixed location on your hard disk, and
  2. there wasn’t an example of how to parse the output.

Number one is fairly trivial: you can either put the supporting script, SOAPXMLRPCHandler.scpt, in the standard location, which is in the computer’s /Library/Scripts directory—the one for all users, not your local version, though it should probably check both—or you can edit the InitSOAP subroutine to tell it to look for the script elsewhere.

Number two is harder, and I spent some time working through it last night. The trick is in knowing that various parts of the return have to be explicitly transformed either to lists or records before their parameters can be read. Once you do that, it’s fairly simple to parse the output.

I’ve hacked a quick demo script that is actually somewhat useful. Until I work out all the bugs, it will be available as a separate download; after that, I’ll probably bundle it with AmazonHandler. The script, Look Up Current Track in Amazon, talks to iTunes to get information about the currently playing track, then looks up the track’s album (or artist, if no album title is available) at Amazon, tells you what Amazon’s current price is, and offers you the option to go to Amazon’s page for the product should you wish to consider the option of purchasing it. So (buzzword version) this script integrates iTunes and Amazon using SOAP-based web services.

The script is available for download on my Scripts page.