Have alook at a very old post of mine:

http://terraqueous.f2o.org/dgdev/viewtopic.php?t=288

It looks at screen dumps but I think you can use the same process.