Indesign CS6 - Rename all colors with color value

Hello!

I’m looking to create a simple script to select all unused colors, remove them, convert all spot colors to process CMYK and then rename all swatches that are left with their color value. I have the first two covered but I’m struggling finding anything on how to rename the colors by the color value (CMYK mix).

Script so far:

tell application "Adobe InDesign CS6"
	tell document 1
		set model of every color whose model is spot to process
		delete unused swatches
		--fail below
		--set name of every color to color value
	end tell
end tell

Any help would be greatly appreciated…thank you very much.

Sudno

Model: Mac
AppleScript: 2.43
Browser: Firefox 25.0
Operating System: Mac OS X (10.8)

I have gotten a little bit further but the script is only renaming one swatch…hmmm

Update:

tell application "Adobe InDesign CS6"
	tell document 1
		delete unused swatches
		set allSwatches to every swatch
		set swatchCount to count of allSwatches
		set thisSwatch to item swatchCount of allSwatches
		set swatchColor to color value of thisSwatch
		set ccc to ((item 1 of swatchColor) as integer)
		set mmm to ((item 2 of swatchColor) as integer)
		set yyy to ((item 3 of swatchColor) as integer)
		set kkk to ((item 4 of swatchColor) as integer)
		set swatchMix to ("C-" & ccc & "  M-" & mmm & "  Y-" & yyy & "  K-" & kkk) as string
		repeat with i from 1 to count of colors
			try
				set properties of color i to {space:CMYK, model:process, name:swatchMix}
			end try
		end repeat
	end tell
end tell

Thanks again in advance,

Sudno

Try this:

tell application "Adobe InDesign CS6"
	tell document 1
		delete unused swatches
		set allSwatches to every swatch
		set swatchCount to count of allSwatches
		repeat with i from 1 to swatchCount
			set thisSwatch to item i of allSwatches
			set swatchColor to color value of thisSwatch
			set ccc to ((item 1 of swatchColor) as integer)
			set mmm to ((item 2 of swatchColor) as integer)
			set yyy to ((item 3 of swatchColor) as integer)
			set kkk to ((item 4 of swatchColor) as integer)
			set swatchMix to ("C-" & ccc & " M-" & mmm & " Y-" & yyy & " K-" & kkk) as string
			try
				set properties of color i to {space:CMYK, model:process, name:swatchMix}
			end try
		end repeat
	end tell
end tell

Hey Shane,

Thank you so much for responding… I’m now getting the following error when running your script:

Adobe InDesign CS6 got an error: Can’t get color value of swatch id 14 of document id 14.

Thoughts?

Not all swatches have color values – color “None” is swatch id 14. So you need to check for that (and for any RGB colours, because they won’t have four values for color value).

Try this:

tell application "Adobe InDesign CS6"
	tell document 1
		delete unused swatches
		set allSwatches to every swatch
		set swatchCount to count of allSwatches
		repeat with i from 1 to swatchCount
			set thisSwatch to item i of allSwatches
			if name of thisSwatch is not "None" and space of thisSwatch is CMYK then
				set swatchColor to color value of thisSwatch
				set ccc to ((item 1 of swatchColor) as integer)
				set mmm to ((item 2 of swatchColor) as integer)
				set yyy to ((item 3 of swatchColor) as integer)
				set kkk to ((item 4 of swatchColor) as integer)
				set swatchMix to ("C-" & ccc & " M-" & mmm & " Y-" & yyy & " K-" & kkk) as string
				set properties of swatch i to {space:CMYK, model:process, name:swatchMix}
			end if
		end repeat
	end tell
end tell

Hi Shane,

Thank you very much! It’s not picking up all of the colors but this works well enough.

I really appreciate your assistance.