Copy link to clipboard
Copied
var myDocument = app.activeDocument;
function trashUnusedSwatch(){
while (myDocument.unusedSwatches[0].name != "") {
id = myDocument.unusedSwatches[0].id;
sw = myDocument.swatches.itemByID(id);
sw.remove();
}
}
What's wrong here?
Again, be clear about what's not working. Are you losing some swatches, none? Is there an error? I assume you're calling the trashUnusedSwatch() later on in your script?
I wouldn't rely on the unnamed swatches not being randomly at the 0 position, so this alternative may be better:
var mydoc = app.documents[0];
var mydeleteswatches = mydoc.unusedSwatches;
for (i = mydeleteswatches.length - 1;i >=0; i--) {
var mydeleteswatch = mydeleteswatches[i];
if (mydeleteswatch.name != "") {
...
Copy link to clipboard
Copied
You may want to try
var myDocument = app.activeDocument;
var unused = myDocument.unusedSwatches;
var n = unused.length;
while (n--) unused[n].remove();
Copy link to clipboard
Copied
Again, be clear about what's not working. Are you losing some swatches, none? Is there an error? I assume you're calling the trashUnusedSwatch() later on in your script?
I wouldn't rely on the unnamed swatches not being randomly at the 0 position, so this alternative may be better:
var mydoc = app.documents[0];
var mydeleteswatches = mydoc.unusedSwatches;
for (i = mydeleteswatches.length - 1;i >=0; i--) {
var mydeleteswatch = mydeleteswatches[i];
if (mydeleteswatch.name != "") {
mydeleteswatch.remove();
}
}
Copy link to clipboard
Copied
Sorry about that. I'm piecing together a file cleaning script to keep my files organized for print. Thanks so much for your help.