• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Automated Removal of Unused Swatches in Book File and Documents

Participant ,
Dec 10, 2023 Dec 10, 2023

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.

TOPICS
How to

Views

258

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Dec 19, 2023 Dec 19, 2023
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
...

Votes

Translate

Translate
Guru ,
Dec 11, 2023 Dec 11, 2023

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 11, 2023 Dec 11, 2023

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 19, 2023 Dec 19, 2023

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");
Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 20, 2023 Dec 20, 2023

Copy link to clipboard

Copied

LATEST

Great Job Anantha, thank you!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines