I don't have this working perfectly yet, but enough to be worth documenting. It might save someone (like me, in a month) half a day's work working out the details.
The intention was to get MUSHclient to lookup a word, as in using a thesaurus, using Word as the thesaurus engine, as a lot of people would have Word installed.
For a start, to do this you will need a COM object. I have tried to do it in Lua, with partial success. Maybe the problem is the Lua COM implementation. ;)
Here is the code for a proposed "lookup word" alias:
I couldn't get the COM interface to create a new object and add a new Word document, so for this to work you need to start Word yourself, and have an empty document open.
Then this should insert the wanted word as word 1 in the document (InsertBefore) and look up the thesaurus (CheckSynonyms). Then the word you replace it with is recovered (doc.Words (1).Text) and displayed in the output window.
Apart from the annoyance of having to start Word, and the possibility this would corrupt any existing Word document you might have open, it also has the annoyance that it only works once. Trying it a second time seems to hang Word, or at least it does for my version.
Maybe some COM expert out there can see what I am doing wrong. However it is a starting point for the general idea.
The intention was to get MUSHclient to lookup a word, as in using a thesaurus, using Word as the thesaurus engine, as a lot of people would have Word installed.
For a start, to do this you will need a COM object. I have tried to do it in Lua, with partial success. Maybe the problem is the Lua COM implementation. ;)
Here is the code for a proposed "lookup word" alias:
require "luacom"
function GetSynonym (name, line, wildcards)
word = luacom.GetObject("Word.Application")
if not word then
ColourNote ("white", "red", "Word is not running")
return
end -- if
word.Visible = true -- make Word visible
word:Activate () -- bring Word to the front
if word.Documents.count == 0 then
ColourNote ("white", "red", "No document open in Word")
return
end -- if
doc = word.ActiveDocument -- get active document
doc.Words (1):InsertBefore (wildcards [1] .. " ")
doc.Words (1):CheckSynonyms ()
-- show resulting word
ColourNote ("white", "blue", doc.Words (1).Text)
ActivateClient () -- reactivate MUSHclient
-- release COM objects
doc = nil
word = nil
end -- function
I couldn't get the COM interface to create a new object and add a new Word document, so for this to work you need to start Word yourself, and have an empty document open.
Then this should insert the wanted word as word 1 in the document (InsertBefore) and look up the thesaurus (CheckSynonyms). Then the word you replace it with is recovered (doc.Words (1).Text) and displayed in the output window.
Apart from the annoyance of having to start Word, and the possibility this would corrupt any existing Word document you might have open, it also has the annoyance that it only works once. Trying it a second time seems to hang Word, or at least it does for my version.
Maybe some COM expert out there can see what I am doing wrong. However it is a starting point for the general idea.