Neil, see my macro, which is mostly AppleScript:
For more information, see the wiki Searching the Forum for Answers section.