//swatch_switch.jsx /* This InDesign CS3 JavaScript will search through all swatches in a document and replace original swatches with the "copy" swatch it finds. A copy swatch is defined as a swatch that ends with the suffix "copy". The script will report any swatches that could not be switched. The default "[Black]" swatch cannot be removed/switched so it will always appear in the report. */ var myDocument = app.activeDocument; var myTotalSwatches = myDocument.swatches.count(); var mySwatchErrors = new Array(); //array of swatches that could not be removed/replaced/switched for (i = 0; i < myTotalSwatches; i++) { myTempString = myDocument.swatches.item(i).name; myTempStringSlice = myTempString.slice((myTempString.length-4), myTempString.length); try // try to replace the old swatch with the new "copy" one { if (myTempStringSlice == 'copy') // If the swatch is a "copy" swatch { //Get the names of the old swatch and the one we'll replace it with myNewSwatchName = myTempString; myOldSwatchName = myTempString.slice(0, myTempString.length-5); //Remove the old swatch myOldSwatch = myDocument.swatches.itemByName(myOldSwatchName); myOldSwatch.remove(myNewSwatchName); //Rename the new swatch with the name of the old swatch myNewSwatch = myDocument.swatches.itemByName(myNewSwatchName); myNewSwatch.name = myOldSwatchName; //Reset the loop if you find a 'copy' swatch and start looking again myTotalSwatches = myDocument.swatches.count(); i = 0; } } catch(e) { mySwatchErrors[i] = myOldSwatchName; } } //Inform user which swatches could not be switched var myErrorReport = mySwatchErrors.join(" "); alert(myErrorReport, "The following swatches could not be switched");