selected word from Microsoft word using applescript

selected word from Microsoft word using applescript

Post by dileep_mat » Thu, 23 Oct 2003 20:58:35


Dear all
I am writing an application using Carbon and Applescript on Mac
OS X ver10.1.5. The aim of this application is fetching selected word
from Microsoft word. I am able to get word using applescript but
resultdata is NULL .

How to solve this problem. please help me. My code is given below.


#include <Carbon/Carbon.h>

void main()
{

SimpleRunAppleScript(
"tell application \"Microsoft Word\" \n"
" set theString to contents of selection as string \n"
" display dialog theString \n" // this dialog is coming with
selected word
" return theString \n"
"end tell");

}

static OSStatus LowRunAppleScript(const void* text, long textLength,
AEDesc *resultData) {
ComponentInstance theComponent;
AEDesc scriptTextDesc;
OSStatus err;
OSAID scriptID, resultID;
theComponent = NULL;
AECreateDesc(typeNull, NULL, 0, &scriptTextDesc);
scriptID = kOSANullScript;
resultID = kOSANullScript;
theComponent = OpenDefaultComponent(kOSAComponentType,
typeAppleScript);
if (theComponent == NULL) { err = paramErr; goto bail; }
err = AECreateDesc(typeChar, text, textLength, &scriptTextDesc);
if (err != noErr) goto bail;
err = OSACompile(theComponent, &scriptTextDesc,
kOSAModeNull, &scriptID);
if (err != noErr) goto bail;
err = OSAExecute(theComponent, scriptID, kOSANullScript,
kOSAModeNull, &resultID);
if (resultData != NULL) {
AECreateDesc(typeNull, NULL, 0, resultData);
if (err == errOSAScriptError) {
OSAScriptError(theComponent, kOSAErrorMessage,
typeChar, resultData);
} else if (err == noErr && resultID != kOSANullScript) {
OSADisplay(theComponent, resultID, typeChar,
kOSAModeNull, resultData);
}
}
bail:
AEDisposeDesc(&scriptTextDesc);
if (scriptID != kOSANullScript) OSADispose(theComponent,
scriptID);
if (resultID != kOSANullScript) OSADispose(theComponent,
resultID);
if (theComponent != NULL) CloseComponent(theComponent);
return err;
}
static OSStatus SimpleRunAppleScript(const char* theScript)
{
return LowRunAppleScript(theScript, strlen(theScript), NULL);
}


bye