Have some Applescript adapted from somewhere a few years ago, but it's got a problem I can't understand: it quits at the "export" line with the message error "The variable targetDocument is not defined." number -2753 from "targetDocument"
Here's the script - what's wrong with the variable...