Copy link to clipboard
Copied
Hello,
I am working with a book file that contains 300 documents. I am looking for a script that can automatically clean up the Swatches panel for each document and remove any unused swatches. Is there a script available to handle this task without the need for manual intervention?
Thank you.
Check this code:
var myFileLocation = Folder.selectDialog("Please select path to files"); // file path selection
var myFolder = new Folder(myFileLocation);
var myFolderContents = myFolder.getFiles("*.indb"); // array
var myFileAmount = myFolderContents.length;
// Check if any .indb files were found
if (myFileAmount === 0) {
alert("No INDB files found in the selected folder.");
} else {
// Loop through the INDB files
for (var i = 0; i < myFileAmount; i++) {
var inFile = myF
...
Copy link to clipboard
Copied
Check out the Delete unused swatches in the Clean up scripts section here. You can run it from the batch processor.
Copy link to clipboard
Copied
Hi Kasyan,
I executed the batch processor while simultaneously browsing through the "unused swatches" script in the script folder of Adobe InDesign. After 40 minutes, I received the completion message and felt satisfied. However, upon opening a few documents by accident, I noticed that unused swatches were still present, and the script job hadn't deleted them. I'm using InDesign 2019, and I'm wondering if the script might not be compatible with this version and might require a more recent update.
Copy link to clipboard
Copied
Check this code:
var myFileLocation = Folder.selectDialog("Please select path to files"); // file path selection
var myFolder = new Folder(myFileLocation);
var myFolderContents = myFolder.getFiles("*.indb"); // array
var myFileAmount = myFolderContents.length;
// Check if any .indb files were found
if (myFileAmount === 0) {
alert("No INDB files found in the selected folder.");
} else {
// Loop through the INDB files
for (var i = 0; i < myFileAmount; i++) {
var inFile = myFolderContents[i];
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
// Open the INDB file
var doc = app.open(inFile);
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
// Access the book contents
var bookContents = doc.bookContents;
// Loop through the book contents (individual documents in the book)
for (var j = 0; j < bookContents.length; j++) {
var bookItem = bookContents[j];
var tempDoc = app.open(bookContents[j].fullName);
var myDocument = app.activeDocument;
var id, sw;
while (myDocument.unusedSwatches[0].name != "") {
id = myDocument.unusedSwatches[0].id;
sw = myDocument.swatches.itemByID(id);
sw.remove();
}
}
}
}
var documents = app.documents;
for (var i = documents.length - 1; i >= 0; i--) {
documents[i].close(SaveOptions.YES);
}
app.activeBook.close(SaveOptions.YES);
alert("Done");
Copy link to clipboard
Copied
Great Job Anantha, thank you!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now