color killer/conversion script

Steve Mills smills at multi-ad.com
Tue Nov 13 10:52:08 CST 2007


On Nov 13, 2007, at 10:08:55, Rick Gaskin wrote:

> i still plagued by extra colors being added to my color lsit every  
> time i bring in colorized element (text, geo blocks etc etc) from  
> another doc.
>
> so, i got to thinkin (i have no idea how this script could be  
> written but it shouldn't be hard - i have something similar written  
> by our friend SM which kind of sort of does the sme thing with  
> hidden glyphs - ie searches out text blocks and if a certain  
> condition  exists or a certain anamoly is found ...it will fix the  
> text)
>
> why couldn't script be written that would look at every element in  
> the doc. when it encountered a element with a particular color it  
> would automatical convert it to the correct color...
>
> in other words, upon activation the script looks at every element,  
> when it finds an element and the color with anamolous color (ex:  
> Blue 1, Blue 2, etc or Red 1, Red 2 etc  - essentially any color  
> name followed by a space and numeral) that it would convert it to  
> another color from the color list - create peset set conversion   
> Blue 1 = Blue; Blue 2 = Blue;
>
> the script could go further and delete the rogue color after its  
> been converted
>
> he example below doesn't work and i am sure there in reality it  
> would be more complex but  blue 1 make it blue

As long as you're OK with the script having hard-coded color names in  
it, and you're OK knowing that no matter where the color came from, it  
will be replaced (what if somebody really wanted 2 different Blues of  
slightly different tints and named them Blue and Blue 1?).

To make sure you get every element at every level on every spread, you  
need to use 3 main loops; one for doc spreads, one for master spreads,  
and one for text flows. The doc spreads and master spreads can be  
handled in the same way, so use a function to handle both lists  
instead of writing it twice. For flows, you need to check each  
character run AND all elements inside each embedded spread (named  
"embedded group" in AppleScript terminology).

To make it somewhat easier, spreads have a "full contents" and "full  
embedded contents" properties. The latter includes elements in  
embedded spreads in flows, which makes your text flow loop easier.  
Both of these return a flat list of all elements however deeply  
contained they are. Here's the basic loop for elements:

set elems to full embedded contents of spread 1 of document 1
set num to number of items of elems

repeat with i from 1 to num
	set e to item i of elems
	
	if fill color of e is "Blue 1" then
		say "yup"
	end if
end repeat

The line that says "yup" is where you'd do the color replacement.  
You'll also need a bunch more logical expressions in the "if" to  
handle all possible color names. Put that into a function and call the  
function once for every spread and once for every master spread. Then  
you'll need a slightly different loop for text flows.

If you aren't able to write the script, let me know and I'll see if I  
can find some time to help out more. And keep in mind that the next  
major release of Creator will have a feature that will make finding  
and replacing this sort of thing a snap. You'll have to weigh the time  
spent writing the script against the time you'll have to wait for that  
feature and decide if the script is worth it.

_________________________________________________________
Steve Mills                              Me: 952-401-6255
Senior Software Architect                         MultiAd
smills at multiad.com                       www.multi-ad.com




More information about the Creator mailing list