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

Clean up InDesign project folders

Community Expert ,
Aug 15, 2022 Aug 15, 2022

Copy link to clipboard

Copied

Hey gang,

Is there a script or method that can look in a Links folder and see which files are NOT being used in the InDesign layout? Having identified them, those extra graphics could be moved or deleted. That is what I am trying to accomplish. Any good ideas?

Mike Witherell
TOPICS
How to

Views

450

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

Community Expert , Aug 17, 2022 Aug 17, 2022

Here‘s a version with a dialog that let‘s you name the new folder. It’s working for me, but if you get an error post a capture:

 

 

 

 

cleanLinks()
/**
* Moves the document links to a named folder  
*/
function cleanLinks(){
    var fn;
    var d = app.dialogs.add({name:"Enter a New Folder Name", canCancel:true});
    with(d.dialogColumns.add()){
        fn = textEditboxes.add({editContents:" ", minWidth:250});
    }
    if(d.show() == true){
        fn = fn.editContents
        d.destroy();
	}
...

Votes

Translate

Translate
Advocate ,
Aug 15, 2022 Aug 15, 2022

Copy link to clipboard

Copied

Hi Mike:

I tend to put unused files on the pasteboard. From the Links panel you can see these files indicated by PB in the far right column. Easy to delete or move from there. Does this help?

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
Community Expert ,
Aug 15, 2022 Aug 15, 2022

Copy link to clipboard

Copied

Hi Scott,

This is more a matter of files that were planned to be used, got put in the Links folder, but then either never got used, or were later deleted from the layout. Now the Links subfolder has extra stuff. I want to hunt for all files not being used in the InDesign file.

 

I suppose I could check links, package, then get rid of old folders, but I thought someone might have a clever script or method.

 

I hope you are well!

Mike Witherell

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
Community Expert ,
Aug 15, 2022 Aug 15, 2022

Copy link to clipboard

Copied

Hi @Mike Witherell 

How about package the document. This will pull all the used files into the new Links folder, then you can delete the original folder.

-Manan

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
People's Champ ,
Aug 16, 2022 Aug 16, 2022

Copy link to clipboard

Copied

How about: Select all images in the Links panel, embed them, delete all images in the Links folder, then unembed back into the Links panel...

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
Community Expert ,
Aug 16, 2022 Aug 16, 2022

Copy link to clipboard

Copied

Clever! 

I kinda wish Bridge had the answer. In Bridge, you can right-click the INDD file and have it show all links.

I sorta want the opposite of that, too.

Mike Witherell

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
Community Expert ,
Aug 16, 2022 Aug 16, 2022

Copy link to clipboard

Copied

Actually, come to think of it: Bridge can show all Links. Then I could set them to 5 Stars rating. Then sort by Rating and I would be able to tease out which files were not starred.

 

I wonder if that is Bridge scriptable?

Mike Witherell

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
Community Expert ,
Aug 16, 2022 Aug 16, 2022

Copy link to clipboard

Copied

If script is something that you are after. The following InDesign script should work. Prerequisties for the script to run are

  • The document should be open
  • The script will search for link files in the folder where the first link it finds in the document is present. Ideally this means that all the placed files should be present in the same folder

 

var linksNames = app.documents[0].links.everyItem().name
var linksFldr = File(app.documents[0].links[0].filePath).parent
var flCol = linksFldr.getFiles()
for(var i = 0; i < flCol.length; i++){
	var fn = File(flCol[i]).displayName
	var rg = new RegExp("\\b" + fn + "\\b")
	if(!rg.test(linksNames))
        File(flCol[i]).remove()
}

 

-Manan

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
Community Expert ,
Aug 16, 2022 Aug 16, 2022

Copy link to clipboard

Copied

In addition to the good information above, some links may have their own links (an Illustrator file for example) these "linked links" are only needed if the placed file needs to be edited, but in my experience they may be saved in the InDesign links folder and would not be collected with the packaged files. Here is an old link to a related discussion: https://community.adobe.com/t5/indesign-discussions/is-there-a-system-for-sorting-graphics-that-are-...

 

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
Community Expert ,
Aug 17, 2022 Aug 17, 2022

Copy link to clipboard

Copied

Manan, thank you. Could you please describe what your script does and does not do? for example, does it delete any files?

Mike Witherell

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
Community Expert ,
Aug 17, 2022 Aug 17, 2022

Copy link to clipboard

Copied

Hi @Mike Witherell,

The script checks in the folder where the asset of the first link it finds in the document resides. This is set as the folder that is to be cleaned up. Then it searches every filename in this folder in the filename collection of the links placed in the indesign file. If the filname is found in the collection the file is skipped, if the name is not found that means the file is not placed in InDesign and henc it is deleted.

So yes the script does delete files. Give it a try with a sample document.

-Manan

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
Community Expert ,
Aug 17, 2022 Aug 17, 2022

Copy link to clipboard

Copied

Hi Manan and Mike, Another option might be to use the link’s copyTo() method, which is the equivalent of the Link Panel’s Utilities>Copy Link(s) to... menu item. In this case the document links could be in any folder, and files that are not linked don’t get trashed. You could also do this manually via the UI, but in that case the links get copied—the script moves the use files without trashing the unused files:

 

 

 

 

 

 

var doc = app.activeDocument;
var dp = doc.filePath
var dl = doc.links.everyItem().getElements()
var nlf = new Folder(dp + "/UsedLinks");
nlf.create();
var lp
for (var i = 0; i < dl.length; i++){
    lp = dl[i].filePath
    dl[i].copyLink(nlf);
    File(lp).remove();
};   

 

 

 

 

 

 

Screen Shot.png

 

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
Community Expert ,
Aug 18, 2022 Aug 18, 2022

Copy link to clipboard

Copied

LATEST

Nice idea Rob. I see I missed most of the action and the thread progressed well. As far as I know the undo actions are for the changes we make on the document so any external changes done would be permanent, so adding an undo for file delete would not be possible.

-Manan

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
Community Expert ,
Aug 17, 2022 Aug 17, 2022

Copy link to clipboard

Copied

Dear Manan and Rob Day,

Thank you both for posting these scripts. Both work. Manan's delete files instantly. Rob's moves them to a new folder and adjusts the Links and does not delete files. Both work well.

Question 1: Could this be made Undo-able? (as in that code method the Theunis de Jong posted about a couple years ago?)

Question 2: Could these scripts be made to announce an onscreen alert so as to indicate that they have completed something? (They both do what they do without any fanfare or user alert interaction. I had to look in the subfolders to see that something had been changed.)

Mike Witherell

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
Community Expert ,
Aug 17, 2022 Aug 17, 2022

Copy link to clipboard

Copied

There is the doScript method that lets you undo a script, but I don’t think it will let you undo Finder/Explorer operations—Manan might know more about that. An alert is easy:

 

app.doScript(cleanLinks,ScriptLanguage.JAVASCRIPT,[],UndoModes.ENTIRE_SCRIPT,'cleanLinks');

/**
* Moves the document links to a folder named UsedLinks  
*/
function cleanLinks(){
    var fn = "UsedLinks"
    var doc = app.activeDocument;
    var dp = doc.filePath
    var dl = doc.links.everyItem().getElements()
    var nlf = new Folder(dp + "/" + fn);
    nlf.create();
    var lp
    for (var i = 0; i < dl.length; i++){
        lp = dl[i].filePath
        dl[i].copyLink(nlf);
        File(lp).remove();
    }; 
    alert("Links Have Been Moved to " + fn)  
}

 

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
Community Expert ,
Aug 17, 2022 Aug 17, 2022

Copy link to clipboard

Copied

Thanks Rob!

Yes, I doubt there is an undo possible here.

Just playing around on my own, I added an alert, but I am probably over-elaborating the code:

var doc = app.activeDocument;
var dp = doc.filePath
var dl = doc.links.everyItem().getElements()
var nlf = new Folder(dp + "/UsedLinks");
nlf.create();
var lp
for (var i = 0; i < dl.length; i++){
    lp = dl[i].filePath
    dl[i].copyLink(nlf);
    File(lp).remove();
};
var doc = app.activeDocument;
alert ("Links gathered into the new UsedLinks subfolder");

 

 

Mike Witherell

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
Community Expert ,
Aug 17, 2022 Aug 17, 2022

Copy link to clipboard

Copied

I haven’t test mine very much—not sure if this is a problem, but if you run the script multiple times on the same document, the links are going to get renamed and appended with _1. It would be possible to add a dialog that asks you to name the new folder.

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
Community Expert ,
Aug 17, 2022 Aug 17, 2022

Copy link to clipboard

Copied

True, and in fact I couldn't get your latest version of script to work. I don't have enough experience to know why, but the one like it that I hacked does work. Thanks for helping me experiment and learn a bit!

Mike Witherell

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
Community Expert ,
Aug 17, 2022 Aug 17, 2022

Copy link to clipboard

Copied

Here‘s a version with a dialog that let‘s you name the new folder. It’s working for me, but if you get an error post a capture:

 

 

 

 

cleanLinks()
/**
* Moves the document links to a named folder  
*/
function cleanLinks(){
    var fn;
    var d = app.dialogs.add({name:"Enter a New Folder Name", canCancel:true});
    with(d.dialogColumns.add()){
        fn = textEditboxes.add({editContents:" ", minWidth:250});
    }
    if(d.show() == true){
        fn = fn.editContents
        d.destroy();
	}

    var doc = app.activeDocument;
    var dp = doc.filePath
    var dl = doc.links.everyItem().getElements()
    var nlf = new Folder(dp + "/" + fn);
    nlf.create();
    var lp
    for (var i = 0; i < dl.length; i++){
        lp = dl[i].filePath
        dl[i].copyLink(nlf);
        File(lp).remove();
    }; 
    alert("Links Have Been Moved to " + fn)  
}

 

 

 

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
Community Expert ,
Aug 17, 2022 Aug 17, 2022

Copy link to clipboard

Copied

Rob, thank you. I very much like your last effort here. It makes me feel like I am in control of it, and it sums up at the end with a message. Very elegant, and just what I need to clean up after messy projects!  Thanks again!

Mike Witherell

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