Changing color in quark 6 stylesheets

Hi,

I am developing an applescript to change Cyan color to other color (example, Black or Yellow) in all quark Stylesheet.

The script asks the replacement color as user input and then it changes Cyan color to user input color in all stylesheets. The problem here is, when the user enters the replacement color, the script does not changes the color in stylesheets, instead it shows an error message.

Below is my script.

set replaceColor to "" as string
tell application "QuarkXPress"
	tell document 1
		set repcolor to display dialog "Enter the replacement color for CYAN: " default answer "" buttons {"Change"} default button "Change"
		set replaceColor to text returned of repcolor as string
	end tell
end tell
tell application "QuarkXPress"
	activate
	if document 1 exists then
		tell document 1
			set paragraphStyles to name of every style spec whose name is not equal to "Normal"
			repeat with i from 1 to count paragraphStyles
				if ((name of color of character attributes of style spec (item i of paragraphStyles)) as string is equal to "Cyan") then
					set color of character attributes of style spec (item i of paragraphStyles) to replaceColor
				end if
			end repeat
		end tell
	end if
end tell

When I changed the line,
From: set color of character attributes of style spec (item i of paragraphStyles) to replaceColor
To: set color of character attributes of style spec (item i of paragraphStyles) to “Black”
then the script work fine.

Could you help me on this.

NOTE: I want the replacement color as user input.

Thanks,
Gopal

It’s because when the string “Black” is typed after the declaration of the object ‘color’ Quark coerces the string class into a color spec name class, when it’s a variable that is a string class, the coercion doesn’t fly.

Try:

set replaceColor to "" as string
tell application "QuarkXPress"
	tell document 1
		set repcolor to display dialog "Enter the replacement color for CYAN: " default answer "" buttons {"Change"} default button "Change"
		set replaceColor to name of color spec (text returned of repcolor)
	end tell
end tell
tell application "QuarkXPress"
	activate
	if document 1 exists then
		tell document 1
			set paragraphStyles to name of every style spec whose name is not equal to "Normal"
			repeat with i from 1 to count paragraphStyles
				if ((name of color of character attributes of style spec (item i of paragraphStyles)) as string is equal to "Cyan") then
					set color of character attributes of style spec (item i of paragraphStyles) to replaceColor
				end if
			end repeat
		end tell
	end if
end tell

This will also help by throwing an error if the user mistypes or enters a color spec name that doesn’t exist in the document; ie.,

tell application "QuarkXPress"
	tell document 1
		set repcolor to display dialog "Enter the replacement color for CYAN: " default answer "" buttons {"Change"} default button "Change"
		try
			set replaceColor to name of color spec (text returned of repcolor)
		on error
			beep
			display dialog "Color \"" & (text returned of repcolor) & "\" doesn't exist!" buttons {"Cancel"} default button 1
			return
		end try
	end tell
end tell
tell application "QuarkXPress"
	activate
	if document 1 exists then
		tell document 1
			set paragraphStyles to name of every style spec whose name is not equal to "Normal"
			repeat with i from 1 to count paragraphStyles
				if ((name of color of character attributes of style spec (item i of paragraphStyles)) as string is equal to "Cyan") then
					set color of character attributes of style spec (item i of paragraphStyles) to replaceColor
				end if
			end repeat
		end tell
	end if
end tell

Hi pandrake,

Thanks for your help.

Gopal