insert text into ms Word

Simple problem really…
I want to run a shell script, take the output, and paste it into the current IP in a Word document being edited.

I can get everything right up to the ‘paste’ part…

Help…

thanks,
Bob

Need a bunch more info, Bownes. What version of Word? What happens when you try to paste? Why not show us some script?

Hi Bob,

This might be of some help


tell application "Microsoft Word"
	activate
	set cbText to (the clipboard) as Unicode text -- or to whatever
	set content of text object of selection to cbText
end tell

If there is some text selected it will be replaced. If there’s no selection your text will be inserted at insertion point of current document.

System events will work too, as well.


-- stuff
tell application "System Events" to key code 9 using {command down}
-- more stuff

Yannis

Version info: Word 2004 v 11.2

here is the script:



set s to "date"
set y to (do shell script s)


tell front document of application "Microsoft Word"
	activate
	set cbText to y as Unicode text -- or to whatever
	set content of text object of selection to cbText
end tell

When I try to run this from script editor I get a popup with:

Applescript Error

Microsoft Word got an error: Can’t set content of text object of selection of document 1 to “Mon Sep 25 11:13:27 EDT 2006”

If I try your system events example it pastes it into the script editor window.

Bob

Model: PowerBook G4
AppleScript: 1.10.7
Browser: Firefox 1.5.0.7
Operating System: Mac OS X (10.4)

Further datapoint.

I tried insert and paste with similar results:


set s to "date"
set y to (do shell script s)


tell front document of application "Microsoft Word"
	activate
	set cbText to y as Unicode text -- or to whatever
	insert cbText
end tell

results in an applescript error:

Microsoft Word got an error: “Mon Sep 25 11:25:55 EDT 2006” doesn’t understand the insert message.

Model: PowerBook G4
AppleScript: 1.10.7
Browser: Firefox 1.5.0.7
Operating System: Mac OS X (10.4)

Jacques,

that works great. thanks for the clarification!

Bob