Skip to main content
Participating Frequently
November 18, 2011
Answered

need to relink missing links to files with extensions

  • November 18, 2011
  • 3 replies
  • 4825 views

I'm working with files received from another company. All the InDesign files have links listed in the Links palette with no extensions. The actual link files themselves HAVE extensions (mostly .jpg, some .psd, .ai, .pdf, etc.). All the links show up as missing, and when I try to relink them I have to do them all individually, even though all the necessary links are in the same folder (just WITH extensions). I've tried "Relink to Folder" and "Relink File Extension," but because there isn't an extension to begin with, it's just not working. It's really time-consuming to relink them one at a time, since there are about 40 InDesign files that average about 40 links each.

I only have one choice for what file to relink to, since the links are supplied. The file name matches perfectly with what is displayed in the Links panel, all except for the extension. For example, "CBZ70.howtoshootbw.beach1" is displayed in the Links panel, and I want to link to "CBZ70.howtoshootbw.beach1.jpg". I know extra periods in the filename is a big no-no. This is another unfortunate aspect of the project. It is the naming convention used for hundreds of links. I have software for batch file renaming, but for this project, I really want to avoid changing the filenames. This is the first of 12 similar projects, all with the same problem, so my hope is to find a solution that will help both now and in the future.

I posted this in the general InDesign forum (http://forums.adobe.com/message/4033140#4033140), and users there thought this should be scriptable. Can anyone offer any help? Thank you!

This topic has been closed for replies.
Correct answer Jongware

One more thing... Could this script be modified to search any subfolders within the folder I target? This would save me even MORE time. Thank you!


(Last night just as I was typing my answer, my modem blew out! ... So I went to sleep first. )

Can you test this? I don't have a file at hand with links with missing extensions (and in subfolders to boot), but according to the debug output it should be looking down into whatever folders are there.

var i, j, searchfolder;

for (j=0; j<app.documents.length; j++) {

    doc = app.documents;

    imgs = doc.links;

    path = doc.filePath;

    $.writeln("Processing document "+j+" from path "+path);

    searchfolder = searchfolder || new Folder(path);

    searchfolder = searchfolder.selectDlg(

    "Find a path to "+doc.name+"'s images. Should contain "+

        imgs[0].name+".*");

    for (i=0; i<imgs.length; i++)

    {

        // Missing?

    $.writeln("Image "+i);

        if (imgs.status == LinkStatus.LINK_MISSING)

        {

        $.writeln("Missing: "+imgs.name+" lookign in "+searchfolder);

            // Do we have a file?

            imglist = findAnyFileDownThere(imgs.name, searchfolder);

        $.writeln("Found "+imglist.length+" possible replacements.");

            if (imglist.length == 1)

            {

                // Oh yeah

                imgs.relink(imglist[0]);

        $.writeln("Relinked to "+imglist[0]);

            }

        }

    }

}

function findAnyFileDownThere (filename, path)

{

var result, folderList, fl;

result = Folder(path).getFiles (filename+".*");

if (result.length > 0)

  return result;

folderList = Folder(path).getFiles(function(item) { return item instanceof Folder && !item.hidden; });

for (fl=0; fl<folderList.length; fl++)

{

        $.writeln("Looking in: "+path+"/"+folderList[fl].name);

  result = findAnyFileDownThere (filename, path+"/"+folderList[fl].name);

  if (result.length > 0)

   return result;

}

return [];

}

3 replies

rriker21christies
Participant
November 8, 2017

I was curious if anyone could edit the script to work on reverse. I have links in the palette with .eps, but we need to switch to a system that has files with no extension. I tried taking a stab at it, but my knowledge is limited. THANKS!!

Jongware
Community Expert
Community Expert
November 19, 2011

Does this Javascript work for you?

It checks all links and attempts to find 'any' file for unlinked ones. If it finds one (and only one) file, it relinks to it.

I have no idea how you would test if it works correctly

doc = app.activeDocument;

imgs = doc.links;

path = doc.filePath;

for (i=0; i<imgs.length; i++)

{

          // Missing?

          if (imgs.status == LinkStatus.LINK_MISSING)

          {

                    // Do we have a file?

                    imglist = Folder(path).getFiles (imgs.name+".*");

                    if (imglist.length == 1)

                    {

                              // Oh yeah

                              imgs.relink(imglist[0]);

                    }

          }

}

Jongware
Community Expert
Community Expert
November 19, 2011

[Jongware] wrote:

I have no idea how you would test if it works correctly

On further reflection, if you're not feeling too confident about it I could make it generate a report of what it changed.

LSHessAuthor
Participating Frequently
November 19, 2011

(responding here to a question in the other thread)

Hi John,

This is the thread where I pulled the script, hoping to modify it. Not sure if it's got the right structure or not:

http://www.mombu.com/computer_design/indesign/t-rename-and-relink-images-indesign-cs4-osx105-3648503.html

John Hawkinson
Inspiring
November 19, 2011

No, that's definitely not what you want. That is a script that renames all the links in a document (for instance, to give them some structured naming), and then renames files to match. It is fundamentally about renaming and not about finding missing links.

You want one of the scripts that is designed to fix broken links by finding the files (in a directory you specify, typically), and then adjust it to look more broadly than for the one filename it is looking for.