More weirdness: Word + AppleScript

Using Script Editor in OS X (10.3) I try:


set x to name of document 1 of application "Microsoft Word"

while Word is running and with a new black document open (unsaved). I get, when I evealuate this: “Document1”

But now I try to abstract a little and create a function:


on topDoc(prog)
  return document 1 of application prog
end topDoc

set x to name of topDoc("Microsoft Word")

and I get an error: ‘Microsoft Word got an error. Can’t get name of document “Document1”.’

Can anyone explain this?

Hmmmm… not quite sure why that happens. After playing with the code a bit, I found something that works:


on topDoc(prog)
	return a reference to document 1 of application prog
end topDoc

set x to name of topDoc("Microsoft Word")

That fixes it, although I don’t know exactly why

yuck. oh well, thanks for the tip. I looked up references in my Nutshell book, and it’s not clear to me why that would change anything here. I think this is another AppleScript bug.