Skip to main content
Participating Frequently
November 18, 2011
Répondu

need to relink missing links to files with extensions

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!

Ce sujet a été fermé aux réponses.
Meilleure réponse par 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 commentaires

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

                    }

          }

}

John Hawkinson
Inspiring
November 19, 2011

Sigh, you're right. I don't know why I was so resistant to doing it from scratch, there really wasn't all that much to leverage.

I suppose I should contribute something. Since LSHess told us she has 40 documents to do, we might as well make the script operate on all currently open documents, so she can open them all and run the script once:

var i, j;

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

    doc = app.documents;

 

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

            }

        }

    }

}

I would imagine the Links panel is sufficient feedback?

John Hawkinson
Inspiring
November 19, 2011

Thanks. I ran this latest script from John... here's an excerpt of the report in the JavaScript Console window:

Image 6

Missing: CBZ70.bw_feat1.abstract_bw

Found 0 possible replacements.

(it was the same "Found 0 possible replacements" report for all the links)

Jongware, What I meant by

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)

is that all the links for the InDesign document are in one folder, which would usually mean once you find one link, InDesign will find the rest of the links located in that folder.

The location of the folder containing the links is much different now, since the files now live on my company's server instead of the previous location (at the company from whom we got the files). Sorry, I was unclear. For each of the 40-some InDesign files, there is a folder of links. I'd love for the script to ask me where to find the files. I could either point it to one of the 40 folders (which I would prefer), or I could combine all the links into one folder. Either way, I think I need to tell it where to look.

I really appreciate both of your help, and your patience as I try to explain exactly what I'm trying to do.


Well, one of the above scripts would have worked if you jsut moved the ID files in with the links, but here you go, with prompting:

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.selectDialog(

    "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 = searchfolder.getFiles (imgs.name+".*");

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

            if (imglist.length == 1)

            {

                // Oh yeah

                imgs.relink(imglist[0]);

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

            }

        }

    }

}

Edit: err, fixed a typo.

LSHessAuteur
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.