InDesign CS2 replace swatch script?

Hi, we have a huge number of files that we need to replace a colour on. I have been searching but no joy so far, but after reading around I thought of deleting a swatch and then telling InDesign which swatch to use instead.

Basically we need to replace Pantone XXX with Pantone XXX on a couple of hundred files. Can anyone point me in the right direction? Im happy to tweak an existing script.

Thanks!

Hi

this should do what your after.

tell application "Adobe InDesign CS2"
	activate
	tell document 1
		try
			set _Layer to layer 1
			set _NewSwatch to swatch "Black"
			set _OldColour to swatch "Keyline"
			set fill color of every item of all page items whose fill color is _OldColour and item layer is _Layer to _NewSwatch
			set stroke color of every item of all page items whose stroke color is _OldColour and item layer is _Layer to _NewSwatch
		end try
		set properties of every word of every story whose fill color is _OldColour to {fill color:_NewSwatch}
	end tell
end tell

Thanks for that script. I’m trying to automate the whole process, but Im stuck here. Just testing it with CS4 until I get into the office later, I thought the script below would work but it doesn’t change the colour and gets stuck on the close and save part. Any ideas?

Also, I know this will take it over the edge, but is there a way of changing the colour to a swatch that isn’t in the list? For example if Pantone xxx isn’t in the swatch list, add it then use that colour?

set destFolder to choose folder with prompt "Please choose folder containing indesign files"
set tarFolder to choose folder with prompt "Please choose target folder"
set fileList to list folder destFolder without invisibles
tell application "Adobe InDesign CS4"
	repeat with oneFile in fileList
		open (destFolder as Unicode text) & oneFile
		tell oneFile
			try
				set _Layer to layer 1
				set _NewSwatch to swatch "Yell"
				set _OldColour to swatch "Blue"
				set (fill color of every item of all page items whose fill color is _OldColour and item layer is _Layer) to _NewSwatch
				set (stroke color of every item of all page items whose stroke color is _OldColour and item layer is _Layer) to _NewSwatch
			end try
			close saving yes
		end tell
	end repeat
end tell

OK I am making progress, this script will do what I need if the file is already open. If I have multiple files open it only works on the top file.

tell application "Adobe InDesign CS4"
	activate
	tell document 1
		load swatches from "Mac HD:Users:liam:Desktop:test.ase"
		try
			set _NewSwatch to swatch "PANTONE 102 C"
			set _OldColour to swatch "PANTONE 180 C"
			set fill color of every item of all page items whose fill color is _OldColour to _NewSwatch
			set stroke color of every item of all page items whose stroke color is _OldColour to _NewSwatch
			
		end try
		close saving yes
	end tell
end tell

I’d love to make this work on multiple files, by opening them making the colour change then saving and closing the file. Is that too hard to add on?

If I was doing this in the GUI I would NOT be going thru all the doc elements. Nor do you need to in script consider just merging the swatches new for old. Let the app take care of the rest.

tell application "Adobe InDesign CS2"
	activate
	tell document 1
		set New_Colour to import Adobe swatchbook spot color name "PANTONE 102 C"
		set Old_Colour to swatch "PANTONE 180 C"
		New_Colour merge with Old_Colour
	end tell
end tell

All the pantone color books are available as part of the app. No need to load from file.

Thats even better, with the help of a friend from this forum I now have a script that will open the file, replace the colour then save & close. Ace!

Just one more thing (as always!) if for some mad reason the Pantone colour is already in the swatch list, how would I get the script to carry on? Right now it just stops when it see’s the same colour.

set destFolder to choose folder with prompt "Please choose folder containing InDesign files"

tell application "Finder"
	try
		set fileList to every file of entire contents of destFolder as alias list
	on error
		set fileList to every file of entire contents of destFolder as alias as list
	end try
end tell

tell application "Adobe InDesign CS4"
	repeat with oneFile in fileList
		open oneFile
		delay 2
		tell front document
			set New_Colour to import Adobe swatchbook spot color name "PANTONE 102 C"
			set Old_Colour to swatch "PANTONE 180 C"
			New_Colour merge with Old_Colour
			close saving yes
		end tell
	end repeat
end tell

merge with works fine if it’s any colour apart from black, paper etc, as these will through an error, for me that’s where iterating through stroke and fill of page items helped me out, I do appreciate though that bigdrunk is looking at pantone colours only.

OK I think I’ve gone a bit mad here. Every time I show someone the script they keep adding more functions, fgrrr.
So this one will change multiple colours, then remove unused colours at the end.

But if a swatch already exists on the document with the same name as a new one, then the script fails. How can I get the script to check to see if the swatch is already on the file?

set destFolder to choose folder with prompt "Please choose folder containing InDesign files"

tell application "Finder"
	try
		set fileList to every file of entire contents of destFolder as alias list
	on error
		set fileList to every file of entire contents of destFolder as alias as list
	end try
end tell

tell application "Adobe InDesign CS4"
	repeat with oneFile in fileList
		open oneFile
		delay 2
		tell front document
			
			set orangecolor to make color with properties {model:process, color value:{0, 50, 100, 0}, name:"orange"}
			try
				set _NewSwatch to swatch "orange"
				set _OldColour to swatch "Yell"
				set (fill color of every item of all page items whose fill color is _OldColour) to _NewSwatch
				set (stroke color of every item of all page items whose stroke color is _OldColour) to _NewSwatch
			end try
			set orangecolor to make color with properties {model:process, color value:{0, 100, 100, 0}, name:"red"}
			try
				set _NewSwatch to swatch "red"
				set _OldColour to swatch "Pink"
				set (fill color of every item of all page items whose fill color is _OldColour) to _NewSwatch
				set (stroke color of every item of all page items whose stroke color is _OldColour) to _NewSwatch
			end try
			set theUnusedSwatches to unused swatches
			repeat with UnusedSwatch from 1 to count of theUnusedSwatches
				if name of (item UnusedSwatch of theUnusedSwatches) is not "" then
					try
						delete (item UnusedSwatch of theUnusedSwatches)
					end try
				end if
			end repeat
			close saving yes
		end tell
	end repeat
end tell

Give this a try on a single doc.

tell application "Adobe InDesign CS2"
	activate
	tell document 1
		if not (exists swatch "PANTONE 102 C") then
			-- Its Not here so we'll load it
			set New_Colour to import Adobe swatchbook spot color name "PANTONE 102 C"
		else
			-- Its already here so we'll use it
			set New_Colour to swatch "PANTONE 102 C"
		end if
		if (exists swatch "PANTONE 180 C") then
			set Old_Colour to swatch "PANTONE 180 C"
			New_Colour merge with Old_Colour
		end if
		delete every item of unused swatches
	end tell
end tell

Hi

Theirs probably a better way to do this, but this does what your after:

set destFolder to choose folder with prompt "Please choose folder containing InDesign files"
tell application "Finder"
	try
		set fileList to every file of entire contents of destFolder as alias list
	on error
		set fileList to every file of entire contents of destFolder as alias as list
	end try
end tell

tell application "Adobe InDesign CS4"
	activate
	repeat with oneFile in fileList
		open oneFile
		delay 2
		tell front document
		
			try
				set orangecolor to color "orange"
			on error
				set orangecolor to make color with properties {model:process, color value:{0, 50, 100, 0}, name:"orange"}
			end try
			
			try
				set _NewSwatch to swatch "orange"
				set _OldColour to swatch "Yell"
				set (fill color of every item of all page items whose fill color is _OldColour) to _NewSwatch
				set (stroke color of every item of all page items whose stroke color is _OldColour) to _NewSwatch
			end try
			
			try
				set redcolor to color "red"
			on error
				set redcolor to make color with properties {model:process, color value:{0, 100, 100, 0}, name:"red"}
			end try
			
			try
				set _NewSwatch to swatch "red"
				set _OldColour to swatch "Pink"
				set (fill color of every item of all page items whose fill color is _OldColour) to _NewSwatch
				set (stroke color of every item of all page items whose stroke color is _OldColour) to _NewSwatch
			end try
			set theUnusedSwatches to unused swatches
			repeat with UnusedSwatch from 1 to count of theUnusedSwatches
				if name of (item UnusedSwatch of theUnusedSwatches) is not "" then
					try
						delete (item UnusedSwatch of theUnusedSwatches)
					end try
				end if
			end repeat
			--close saving yes
		end tell
	end repeat
end tell

That works perfectly, thank you very much!

Hi!
I am trying to replace a RGB swatch with a CMYK color. I have a BrighBlueRGB (0,110,255) that I need to be in pdfs for web and for print I have to replace it with a PrintBlueCMYK (100,80,0,0). The First color is defined as a swatch color in all Indesign files.

I tried to replace via

set PrintBlueCMYK to "100,80,0,0"

set properties of swatch  "BrightBlueRGB" to {model:process, space:CMYK, color value:PrintBlueCMYK}

but all I get is
Can’t set properties of swatch “BlueRGB” to {model:process, space:CMYK, color value:“100,57,0,0”}.

Any ideea?
thanks a lot
Dan