Insertion point problems with Microsoft Word

okay… this is bizarre

I have the script that is supposed to retrieve a word that I am looking at on Merriam-Webster’s Online dictionary and store it in a Microsoft word document. But it runs into a problem whenever i try to enter that word in the document.


global theWord

-- This process retrieves the word

tell application "Safari"
	set bigString to URL of front document
end tell

if bigString contains "&" then
	set text item delimiters to "="
	set L to text items of bigString
	set wordItem to item 3 of L
	set text item delimiters to "&"
	set theWord to text item 1 of wordItem
else
	set text item delimiters to "="
	set L to text items of bigString
	set theWord to last text item of bigString
end if

-- Now that word is stored in a Microsoft word document

set thePath to "Macintosh HD:Users:h3ss2:Documents:Vocab.doc" as alias

tell application "Microsoft Word"
	if name of documents does not contain (thePath as string) then
		open thePath
	end if
	
	--here's the problem tell block
	
	tell text of window "Vocab.doc"
		set contents of insertion point after last word to (return & theWord)
	end tell
	
	--save front document in alias thePath
end tell

When i try and set the variable theWord to a literal string in the top level it inserts the word just fine. But for some reason it won’t work with the word that i pull from the URL. It’s not a class issue. HELP! WHAT’S GOING ON!!!

No it is a class issue. The word that you are extracting from the URL is an Unicode text, not a string like Word needs. You need to coerce it to a string and then all will be fine. Well, almost. You need to return your text item delimiters back to the way you found them after your extraction. Try this:

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]