all open documents, add unnamed colors: swatch clean up
Copy link to clipboard
Copied
I am trying to cycle through all open documents and clean up the swatches pallet by:
- showing unnamed colors
- delete unused swatches
I got the unused swatches to clear, up, but I am having problems knowing how to get the unnamed colors to show up across all open documents. I can use the menu item name to get the page I am on to work, but I am having problems getting it to work across all open documents. I am sure it is a simple script to fix it all.
for(var i = 0; i < app.documents.length; i++){
var myIndesignDoc = app.documents;
app.menuActions.itemByName("$ID/Add All Unnamed Colors").invoke();
var myUnusedSwatches = myIndesignDoc.unusedSwatches;
for (var s = myUnusedSwatches.length-1; s >= 0; s--)
{
var mySwatch = myIndesignDoc.unusedSwatches
;var name = mySwatch.name;
// alert (name);
if (name != ""){
mySwatch.remove();
}
}
}
Copy link to clipboard
Copied
Which version of Indesign are you using?
Copy link to clipboard
Copied
A color is unnamed as long as it hasn't been added to the swatch panel. So a possible approach would be to list swatches before and after you asked InDesign to ass the unnamed Colors. Then you can excerpt the colors that have been added.
Unless I am wrong.
Loic
Copy link to clipboard
Copied
I am using CC 2014
Copy link to clipboard
Copied
What about adding this to a function and creating an event listener for after open or beforeClose? something like this. The below will trash all unused swatches Before save. you can use any event listener in place of "beforeSave" eventlisteners are Here >>>>>>> Need help with Multiple eventListeners <<<<<<<< This worked in my script. This is as stated in an auto start script right now it will need modified if you do not need it to auto start.
#targetengine "AutoStartScript"
app.addEventListener( "beforeSave", doTrashSwatch );
function doTrashSwatch(){
for(var i = 0; i < app.documents.length; i++){
var myIndesignDoc = app.documents;
app.menuActions.itemByName("$ID/Add All Unnamed Colors").invoke();
var myUnusedSwatches = myIndesignDoc.unusedSwatches;
for (var s = myUnusedSwatches.length-1; s >= 0; s--)
{
var mySwatch = myIndesignDoc.unusedSwatches
;var name = mySwatch.name;
// alert (name);
if (name != ""){
mySwatch.remove();
}
}
}
}
Copy link to clipboard
Copied
Let me re phrase that. I didnt have any unused colors in my test script. This deletes all unused swatches (cmyk, Lab Pantone etc..) on any document that is saved. But it does not show unnamed colors.
Copy link to clipboard
Copied
Hello fee1968
Give this code a try…
kind regards
Daniel (from Switzerland)
main();
exit();
function main() {
var myDoc = app.activeDocument;
if (myDoc != null) {
$.writeln("Colors");
// shows all colors also those whithout a name (then the name is empty)
for (var i = 0; i < myDoc.colors.length; i++) {
$.writeln(">" + myDoc.colors.name + "<");
}
$.writeln("Swatches");
for (var i = 0; i < myDoc.swatches.length; i++) {
$.writeln(myDoc.swatches.name);
}
var unusedSwatches = myDoc.unusedSwatches;
$.writeln("\nunused Swatches: " + unusedSwatches.length);
for (var i = unusedSwatches.length -1; i >= 0; i--) {
$.write(unusedSwatches.name);
unusedSwatches.remove();
$.writeln(" deleted");
}
}
}

