Indesign CS Scripting Noob with "fill color" problem

Hello all

I am very new to scripting and trying to figure out how to make things work in InDesign CS before inflicting my madness on the rest of the department. Right now I am experimenting with scripts produced by others but keep running into a problem with setting a “fill color” property that I just cant seem to solve. I’ve come across other scripts using similar fill color commands and they produce similar errors on my machine. I “imagine” these scripts must work for someone (perhaps ID CS2?) but they arent working for me and it really has me stumped.

The following script is one of the examples that produces an error (I’ve separated the line that produces the error). The error I get for the following script is : InDesign CS got an error: Can’t set fill color of every word of parent story of text frame id 212 of page id 178 of spread id 173 of document “Untitled-7” whose contents = “zebra” to color id 193 of document “Untitled-7”

So far it seems I can only set “fill color” and similar properties when I use a set or tell command that instructs indesign to “make” something. When I try to change the property without a “Make” command I get an error.

Can anyone point out what is wrong with the separated line? It is attempting to set all instances of the word “Zebra” found within the textframe to the color red. I get errors every time I try to change the fill color (or stroke color & other properties) of text anywhere without using a “make textframe” command. Any help would be greatly appreciated.

(PS… if this script works for you I would like to know about it… perhaps something is wrong with my version of OSX or applescript?)

--Find preferences example
set myString to "You found:" & return
tell application "InDesign CS"
	--Set up an example document.
	set myDocument to make document
	tell myDocument
		set myColor to make color with properties {color value:{0, 100, 100, 0}, name:"Red"}
	end tell
	tell page 1 of myDocument
		set myTextFrame to make text frame with properties {geometric bounds:{"3p", "3p", "18p", "24p"}, contents:"Aardvark,manatee,zebra,baboon,gorilla,takin,otter,fox,zebra,mollusk,zebra,lemur,zebra."}
	end tell


-- THE FOLLOWING LINE PRODUCES THE ERROR
	tell (words of parent story of myTextFrame whose contents = "zebra") to set fill color to myColor


	--Clear the existing find preferences
	set find preferences to nothing
	set find text of find preferences to "zebra"
	set myFoundWords to search story 1 of myDocument with find attributes {find text:"zebra", fill color:myColor}
	--Display the character ranges (in a "real world"example,you would do
	--something else with the contents of the myFoundWords list).
	repeat with myCounter from 1 to (count myFoundWords)
		set myString to myString & "text from character "
		set myString to (myString & (index of item myCounter of myFoundWords) as string) & " to character "
		set myString to (myString & (index of character -1 of item myCounter of myFoundWords) as string) & return
	end repeat
	activate
	display dialog myString
end tell

Model: G5 dual processor
AppleScript: 1.9.3
Browser: Safari 312.6
Operating System: Mac OS X (10.3.9)

hi,
I checked your script using CS1 and got the same error as you did. I then checked your code which is fine and then looked at your “Zebra” data and found your search for words was in a data string with no spaces between items. If you put spaces into the string to delimit the “words” then you get exactly the result you want.
Hope this works for you.

Riverman, thank you so very much. I’ve spent several hours mucking with this script without finding an acceptable solution. I now realize that indesign’s “word” function only accepts spaces as delimiters, not punctuation (which explains the similar errors I’ve been getting in the other scripts).

I’ll be sure to send you a “thank you” wish everytime I head down to the river from now on :slight_smile: