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");