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

relink images with different names

Contributor ,
Jan 27, 2015 Jan 27, 2015

Copy link to clipboard

Copied

Hi all, I need to relink lots of -missing- images (i.e. "my_favourite_pic_001_LR.jpg") to their high resolution versions (i.e. "my_favourite_pic_001_HR.jpg"). So, is there a way to tell InDesign to 'read' all the characters but the last two before the dot, while searching for links? HR images are all in one folder, so there's no danger to relink wrong ones. I'm pretty a noob with js or applescript, but I'll be glad if someone of you could help me

TOPICS
Scripting

Views

6.6K

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

Mentor , Jan 27, 2015 Jan 27, 2015

Hi,

Here is javascript (place and run from InDesign Script Panel):

var

  sourceFolder = Folder.selectDialog("Show me a source folder"),

  mLinks = app.activeDocument.links.everyItem().getElements(),

  cLink, cFile;

while ( cLink = mLinks.pop() ) {

  if (cLink.status == LinkStatus.NORMAL) continue;

  cFile = File(sourceFolder + "/" + cLink.name.replace("LR.","HR.") );

  if ( !cFile.exists ) continue;

  cLink.relink(cFile);

  }

Jarek

Votes

Translate

Translate
Mentor ,
Jan 27, 2015 Jan 27, 2015

Copy link to clipboard

Copied

Hi,

Here is javascript (place and run from InDesign Script Panel):

var

  sourceFolder = Folder.selectDialog("Show me a source folder"),

  mLinks = app.activeDocument.links.everyItem().getElements(),

  cLink, cFile;

while ( cLink = mLinks.pop() ) {

  if (cLink.status == LinkStatus.NORMAL) continue;

  cFile = File(sourceFolder + "/" + cLink.name.replace("LR.","HR.") );

  if ( !cFile.exists ) continue;

  cLink.relink(cFile);

  }

Jarek

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
Contributor ,
Jan 28, 2015 Jan 28, 2015

Copy link to clipboard

Copied

It's amazing, thanks a lot! However, is there a way to add "MR" images or whatever two letters before the dot, to be all relinked to HR ones?

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
Mentor ,
Jan 28, 2015 Jan 28, 2015

Copy link to clipboard

Copied

Hi,

One can use regex in place on 1st parameter of replace method.

Line 08:

cFile = File(sourceFolder + "/" + cLink.name.replace(/.{2}\./,"HR.")

which means match "any two characters and period"

Jarek

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
Contributor ,
Jan 28, 2015 Jan 28, 2015

Copy link to clipboard

Copied

That's exactly what I was looking for. Thanks a lot Jarek!

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 Beginner ,
Jun 12, 2017 Jun 12, 2017

Copy link to clipboard

Copied

Hey @Jump_Over!

I think this Script might help me! But i need something little different here, is it possible to change the Script in the way i need it? I will try to explain:

I've got a lot of missing images in my indesign file too (linked pdf files), and i want to relink them with new pdf files all with COMPLETE different names. So i would like that the Script automatically relink all missing pdf files with all the new ones with the different names.

It is not necessary in which sequence the pdf files will be replaced, it is only important that all missing files will be replaced with all the new ones. And one last note: The number of old missing files and the new files for relink will be always the same, so for example if i got 30 missing files i want to relink them with 30 new ones.

Thx for any 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
Mentor ,
Jun 13, 2017 Jun 13, 2017

Copy link to clipboard

Copied

AndreasNRW  napisał(-a)

...So i would like that the Script automatically relink all missing pdf files with all the new ones with the different names...

What about the way by which a proper name for relinking is chosen?

Are you going, for example, to create a TXT list with 'old name - new name' lines?

How would you did it manually?

Jarek

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 Beginner ,
Jun 13, 2017 Jun 13, 2017

Copy link to clipboard

Copied

Ok i try to explain it in more detail:

1.) One InDesign Document with 30 pages, on each page i placed only 1 linked pdf file. So i have a Folder with 30 single pdf files, each file only placed once on each of the 30 indesign pages. Each pdf file has a different name.

2.) Now, i got 30 new single pdf files, all new 30 files got new names, all different than the old 30 files which were linked in the indesign document. I only want indesign to automatically re-link/replace all the new 30 pdf files with the old ones, no matter that the new ones got different names. Because they got different names than the old ones, i have to manually re-link every single pdf on every single side at the indesign document and tell indesign which old file to replace with which new file.

EXAMPLE: InDesign PAGE 1 -> PDF-File linked (Name: "Job_A 1467.pdf") – re-link manually with new file (Name: "Job_B 1579.pdf"). If you do this again and again for about 300, 400, 500 pages (sometimes my documents are that big) that is a big effort and takes much time.

The size and file format of the new files will be every time still identical, only the file names are changing. The important one would be that the script automatically replaces all 30 old files with the new 30 files, in which order the new files are replaced doesn’t matter. (sure the most logical order would be to do it like (1,2,3,4 ...) or (A, B, C, D ...)

In other much shorter words: I only want to tell InDesign “you had linked these 300 files”, i delete them or move them, now you are missing them -> NOW please relink it with this new folder also with 300 files, but they got different names, but please DONT care about the different names or in which order they got placed in the indesign document, just relink all 300 old files with the 300 new files from the new folder automatically without asking me for every single page again which file you should take for replacing”.

I hope i managed it to explain my problem so everyone can understand it!

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
Mentor ,
Jun 13, 2017 Jun 13, 2017

Copy link to clipboard

Copied

Hi,

Try this:

var

  sourceFolder = Folder.selectDialog("Show me a source folder"),

  mLinks = app.activeDocument.links.everyItem().getElements(),

  mFiles = sourceFolder.getFiles(function (cFile) {if (cFile instanceof File) return true; return false}),

  cLink, cFile;

while ( cLink = mLinks.pop() ) {

  if (cLink.status == LinkStatus.NORMAL) continue;

  cFile = mFiles.pop();

  if ( !cFile ) break;

  cLink.relink(cFile);

  }

Jarek

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 Beginner ,
Jun 13, 2017 Jun 13, 2017

Copy link to clipboard

Copied

Hey Jump_Over,

wow really big thx for your fast help!! I tried it right now and it worked fine!

But i forgot to mention something....sorry! (i thought it would work that way too but it seems there is a modification needed in the script).

If i got an indesign file with for example 5 pages and on each page only 1 pdf is placed, your script does the job like it should, no problems!

But sometimes i have the same pdf file placed over 2 or 3 indesign pages, but on each page with a different image section (different positioning in the indesign frame where it is placed). I tried your Script with a document where my files are placed like this:

InDesign -> 10 pages, but i've got only 5 linked pdf files, each file palced twice in the indesign document. Your Script now replaced 5 pdf files on 5 indesign pages, the other 5 pages remained untouched with the old missing pdf files.

An example for better understanding how it is build and what i need:

Old Files placed like this:

InDesign Page 1 -> Placed PDF File "Job_A_3.pdf"

InDesign Page 2 -> Placed PDF File "Job_A_3.pdf"

InDesign Page 3 -> Placed PDF File "Job_A_4.pdf"

InDesign Page 4 -> Placed PDF File "Job_A_4.pdf"

(...)

If i get the new files, i would like that it replaces them like they was placed before on each side, like this:

New Files should placed like this:

InDesign Page 1 -> Placed PDF File "Job_B_7.pdf"

InDesign Page 2 -> Placed PDF File "Job_B_7.pdf"

InDesign Page 3 -> Placed PDF File "Job_B_8.pdf"

InDesign Page 4 -> Placed PDF File "Job_B_8.pdf"

(...)

Sorry that i didn't explained that immediately in my first post... you think it is possible to add this to the script ?

Greetings,

AndreasNRW

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
Mentor ,
Jun 14, 2017 Jun 14, 2017

Copy link to clipboard

Copied

Hi,

Yes, that's possible. You (I?) can use a separate function for relinking and checking next steps.

Alike this:

var

  sourceFolder = Folder.selectDialog("Show me a source folder"),

  mLinks = app.activeDocument.links.everyItem().getElements(),

  mFiles = sourceFolder.getFiles(function (cFile) {if (cFile instanceof File) return true; return false}),

  cLink, cFile;

while ( cLink = mLinks.pop() ) {

  if (cLink.status == LinkStatus.NORMAL) continue;

  cFile = mFiles.pop();

  if ( !cFile ) break;

  mRelink(cLink, cFile);

  }

function mRelink(oldLink, newFile) {

    var oldName = oldLink.name;

    do {

        oldLink.relink(newFile);

        oldLink = app.activeDocument.links.item(oldName);

        } while (oldLink.isValid)

    }

Jarek

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 Beginner ,
Jun 18, 2017 Jun 18, 2017

Copy link to clipboard

Copied

Hey, i had the time and tested it with a big indesign file with many pages. That was exactly what I was looking for, it worked perfect! Thank you very much Jarek for your 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
New Here ,
Jan 10, 2018 Jan 10, 2018

Copy link to clipboard

Copied

Hello Jump_Over,

I have large number of files in Indesign say

1. trish.jpg

2. seven eleven.tif

3. vidya_theikty.eps

and on and on

which I wanted to relink to the

1. trish 3c.jpg

2. seven eleven 2c.tif

3. vidya_theikty 4c.eps

can you help me with the scrip.

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 Beginner ,
Jan 17, 2019 Jan 17, 2019

Copy link to clipboard

Copied

Hi man tan! I actually managed to find this Rad Lexus's script, which relinks ALL links with new files based on filesize. So if your files are same size but just different name, this works.

(Here's the link where I found this)

//DESCRIPTION:Find lost images by size

// A Rad Lexus Script 31-Jul-2016

if (!app.documents.length)

{

    alert ('please open a document first');

    exit();

}

problems = [];

path = Folder(app.activeDocument.filePath).selectDlg("Select file source");

if (path)

{

    // load the images in this folder

    filelist = path.getFiles ('*.*');

//  alert (filelist);

    // loop over the images

    for (i=0; i<app.activeDocument.allGraphics.length; i++)

    {

        // is it a linked file?

        if (app.activeDocument.allGraphics.itemLink &&

            app.activeDocument.allGraphics.itemLink.needed)

        {

            size = app.activeDocument.allGraphics.itemLink.size;

            extension = app.activeDocument.allGraphics.itemLink.filePath.substring

                (app.activeDocument.allGraphics.itemLink.filePath.lastIndexOf('.')).toLowerCase();

            // check our list

            matches = [];

            for (j=0; j<filelist.length; j++)

            {

                // extension the same?

                if (extension.localeCompare(filelist.fullName.substring

                    (filelist.fullName.lastIndexOf('.')).toLowerCase()) == 0)

                {

                    // size the same?

                    if (filelist.length == size)

                        matches.push (filelist);

                }

            }

            // did we find a match?

            if (matches.length == 1)

            {

                app.activeDocument.allGraphics.itemLink.relink (matches[0]);

            } else

            {

                if (matches.length == 0)

                    problems.push ('no match for '+app.activeDocument.allGraphics.itemLink.filePath);

                else

                    problems.push ('multiple matches for '+app.activeDocument.allGraphics.itemLink.filePath);

            }

        }

    }

    if (problems.length)

        alert (problems.join('\r'), 'Problems');

}

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 Beginner ,
Jun 21, 2017 Jun 21, 2017

Copy link to clipboard

Copied

Hey Jarek,

I've used your first script (the one for the original query) but after selecting a folder nothing seems to happen. From the original script all I've done is replaced this:

  cFile = File(sourceFolder + "/" + cLink.name.replace("LR.","HR.") );

by that:

  cFile = File(sourceFolder + "/" + cLink.name.replace("low_res","high_res") );

my filename structure is slightly different: low_res_image_1.jpg and high_res_image_1.jpg. Should the above change search for links with the term 'low_res' and replace with the ones that have 'high_res'.

I've tried to places low and high res in the same folder then different folders, no luck! Perhaps you could point me to where I seem to go wrong?

Thanks in advance!

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
Mentor ,
Jun 21, 2017 Jun 21, 2017

Copy link to clipboard

Copied

Hi,

Basically - it should work.

Old files should be missed (hide them to switch link status).

New files should be located in a chosen folder (1 level).

Jarek

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 Beginner ,
Jun 21, 2017 Jun 21, 2017

Copy link to clipboard

Copied

What do you mean by 'hide them to switch link status'? I'm not sure I fully understand what I should do there?

Thanks again!

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
Mentor ,
Jun 21, 2017 Jun 21, 2017

Copy link to clipboard

Copied

I ment to move old files from original folder or to delete them --> in a doc link status will turn to "MISSED" (red circle)

Jarek

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 Beginner ,
Jun 21, 2017 Jun 21, 2017

Copy link to clipboard

Copied

PERFECT! Thanks very much, it works brilliantly, the only thing is that I have to do it individually for each Indd files. Is there a way to apply this script to all open windows for example? That's very minor now... Regardless many thanks for your help Jarek!

antoine.

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
Mentor ,
Jun 21, 2017 Jun 21, 2017

Copy link to clipboard

Copied

antoine_c  napisał(-a)

...Is there a way to apply this script to all open windows for example?...

redefine a source variable:

mLinks = app.documents.everyItem().links.everyItem().getElements()

Jarek

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 Beginner ,
Jan 14, 2019 Jan 14, 2019

Copy link to clipboard

Copied

Hi Jump_Over!

I, too, have a modification request

I copy project folder every week, and need to rename files with week number, eg. week02.pdf -> week03.pdf. Doing this by hand is sometimes time consuming.

Is it possible to have a search/replace kind of code, which asks:

1. source folder

2. search term (week02)

3. replace term (week03)

and then does the renaming to all missing files.

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
Contributor ,
Jan 14, 2019 Jan 14, 2019

Copy link to clipboard

Copied

Hi johanna.pakkala​,

you can try this script

#targetengine batchRelink

var desktopFolder = new Folder("~/desktop");

sourceFolder = desktopFolder.selectDlg("Please select folder");

if (!sourceFolder) {exit();}

var files = sourceFolder.getFiles();

if (files.length == 0) {exit();}

var w = new Window ("palette");

var div = w.add("group");

div.orientation = "column";

var inputDim = [0, 0, 200, 25];

var searchgrp = div.add("group");

searchgrpLabel = searchgrp.add("statictext", undefined, "Search Term: ");

var searchinput = searchgrp.add("edittext", inputDim, undefined);

searchinput.active = true;

var replacegrp = div.add("group");

replacegrpLabel = replacegrp.add("statictext", undefined, "Replace Term: ");

var replaceinput = replacegrp.add("edittext", inputDim, undefined);

var buttons = div.add("group");

buttons.orientation = "row";

var renamebtn = buttons.add("button", undefined, "Rename and relink");

var closebtn = buttons.add("button", undefined, "exit");

closebtn.onClick = function () {w.close();}

renamebtn.onClick = function () {w.close(); renameRelink(files);}

w.show();

function renameRelink (filesArray)

    {

        var searchterm = searchinput.text, replaceterm = replaceinput.text, doc = app.activeDocument;

       

        for (var x = 0; x < filesArray.length; x++)

            {

                var oldname = filesArray.name, newname = "";

               

                if (oldname.search(searchterm) != -1)

                    {

                        newname = oldname.replace(searchterm, replaceterm);

                       

                        filesArray.rename(newname);               

                       

                        for (var i = 0; i < doc.links.length; i++)

                            {

                                if (doc.links.name == oldname)

                                    {

                                        doc.links.relink(File(sourceFolder + "/" + newname));

                                    }

                            }

                       

                    }

            }

       

    }

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 Beginner ,
Jan 15, 2019 Jan 15, 2019

Copy link to clipboard

Copied

Thank you crazyPanda! This was even more than i expected!

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
Mentor ,
Jan 14, 2019 Jan 14, 2019

Copy link to clipboard

Copied

Hi,

First script should work after modifying this line:

cFile = File(sourceFolder + "/" + cLink.name.replace("LR.","HR.") ); 

to (for example ".......week02....." need to be changed to ".......week03.....")

cFile = File(sourceFolder + "/" + cLink.name.replace("week02","week03") ); 

Did you try it?

Jarek

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 Beginner ,
Jan 15, 2019 Jan 15, 2019

Copy link to clipboard

Copied

Yes Jarek, I tried that. I was wondering if script could change link names and relink them from given folder without needing me to modify the code every week

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