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

Relink missing links with script

Community Beginner ,
Oct 03, 2017 Oct 03, 2017

HI everyone, does anyone have a script that can: choose missing links from the active document and relink them to the folder that we also put its path into the script, so that i only need press 1 button to do it?

TOPICS
Scripting
7.9K
Translate
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

Valorous Hero , Oct 04, 2017 Oct 04, 2017

Here I wrote a quick & dirty script for you.

Change the path variable in line 9 to whatever the path you want.

Select an image with black or white arrow and run the script.

var scriptName = "Relink selected link to folder",

doc;

PreCheck();

//===================================== FUNCTIONS ======================================

function Main(image) {

    var file,

    path = "/E/Archive/My folder/", // type the path to your folder here

    link = image.itemLink;

   

    if (link.status == LinkStatus.LINK_M

...
Translate
Engaged ,
Oct 03, 2017 Oct 03, 2017

Hi,

Hope this helps!!

Get the missing links from server

Re: need to relink missing links to files with extensions

Thanks,

Prabu G

Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.
Translate
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 ,
Oct 03, 2017 Oct 03, 2017

Thank Prabu G, its nearly exactly what I am looking for. But one more thing, it is possible to put the path of the folder into the script, so I dont need to choose the folder anymore.

Translate
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
Valorous Hero ,
Oct 04, 2017 Oct 04, 2017

But one more thing, it is possible to put the path of the folder into the script, so I dont need to choose the folder anymore.

I didn't look carefully into the script, but I'd made the following adjustments:

04-10-2017 9-58-26.png

Note: the script processes all open documents and looks for the images starting from the 'root' folder and down there.

Below is my (quick & dirty) modified (totally untested) version:

var i, j, searchfolder; 

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

    doc = app.documents

 

    imgs = doc.links; 

    path = "/E/Archive";  // type here the path for the folder to start

    searchfolder = new Folder(path); 

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

Translate
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 ,
Oct 04, 2017 Oct 04, 2017

Thank you so much Kasyan. I make over 100 documents per day and about 100 photos in each document need to be relinked to only 1 folder. Yes the feature "Relink to folder" is the way I am doing. But in each document, some photos are already relinked and some are not. I just want to speed up workflow by only "pressing a button" and the scipt will: choose missing links in the document I am working on, and relink them to the folder I want (and i want to pass through the dialog box "choosing folder" because I have only 1 folder)

And i am apreciated about the script above but sadly it didnt work .

Translate
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
Valorous Hero ,
Oct 04, 2017 Oct 04, 2017

And i am apreciated about the script above but sadly it didnt work

I just tested the script against a simple test file and it did work for me, though it took about a dozen of secs since it processes all subfolders.

Before

04-10-2017 14-46-35.png

After

04-10-2017 14-47-48.png

Translate
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
Valorous Hero ,
Oct 04, 2017 Oct 04, 2017

Here I wrote a quick & dirty script for you.

Change the path variable in line 9 to whatever the path you want.

Select an image with black or white arrow and run the script.

var scriptName = "Relink selected link to folder",

doc;

PreCheck();

//===================================== FUNCTIONS ======================================

function Main(image) {

    var file,

    path = "/E/Archive/My folder/", // type the path to your folder here

    link = image.itemLink;

   

    if (link.status == LinkStatus.LINK_MISSING) {

        file = new File(path + link.name);

       

        if (file.exists) {

            link.relink(file);

        }

    }

}

//--------------------------------------------------------------------------------------------------------------------------------------------------------

function PreCheck() {

    var image;

    if (app.documents.length == 0) ErrorExit("Please open a document and try again.", true);

    doc = app.activeDocument;

    if (doc.converted) ErrorExit("The current document has been modified by being converted from older version of InDesign. Please save the document and try again.", true);

    if (!doc.saved) ErrorExit("The current document has not been saved since it was created. Please save the document and try again.", true);

    if (app.selection.length == 0) ErrorExit("Nothing is selected.", true);

   

    if (app.selection[0].constructor.name == "Image") {

        image = app.selection[0];

    }

    else if (app.selection[0].images.length == 1) {

        image = app.selection[0].images[0];

    }

    else {

        ErrorExit("There's no image in selection.", true);

    }

    Main(image);

}

//--------------------------------------------------------------------------------------------------------------------------------------------------------

function ErrorExit(error, icon) {

    alert(error, scriptName, icon);

    exit();

}

//--------------------------------------------------------------------------------------------------------------------------------------------------------

Translate
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 ,
Oct 04, 2017 Oct 04, 2017

Hi Kas Servetsky, you are right!!!!!!!!!!!!!!!!!!!! I've just tested the first script again and it works with the folder in my Mac. Yesterday I did with one in our company server so i think i put the wrong path. I'm so sorry about the wrong issue, and thank you so much!

Translate
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
Valorous Hero ,
Oct 05, 2017 Oct 05, 2017

Glad to hear that you sorted it out yourself!

Translate
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 ,
May 02, 2022 May 02, 2022

Hi Kasyan,

with InDesign CC 2018 and above there is a new method to relink links:

 

reinitLink()

DOM documentation:

https://www.indesignjs.de/extendscriptAPI/indesign13/#Link.html#d1e293585__d1e294323

 

The interesting thing with this method:

It does not require an existing file object for relinking, a new linkResourceURI:String is required instead.

That means that we can relink to not yet existing files or to files we have no access to and just know where they should be positioned on a client's file system. That could simplify things…

 

See Mark's correct answer in:

 

Relink an image to a file that does not exist
dona56558947, 3 hours ago
https://community.adobe.com/t5/indesign-discussions/relink-an-image-to-a-file-that-does-not-exist/td...

 

See m1b's (Mark's) code in the same thread:

https://community.adobe.com/t5/indesign-discussions/relink-an-image-to-a-file-that-does-not-exist/m-...

 

Regards,
Uwe Laubender

( ACP )

Translate
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
Valorous Hero ,
May 04, 2022 May 04, 2022

Thank you for pointing this out, Uwe!

— Kasyan

Translate
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 ,
13 hours ago 13 hours ago

Hi Kasyan ( @Kasyan Servetsky ),

while testing reinitLink() I came accross a big surprise (at least for me).

When working on the itemLink of one single instance of a placed image and used reinitLink() on this one instance ALSO all other placed instances will change. Documented in this thread initally from 2019:

 

Exploring Link.relink() function in Javascript and COM
Michael_Rosenstein, Dec 13, 2019

https://community.adobe.com/t5/indesign-discussions/exploring-link-relink-function-in-javascript-and...

 

See my reply from today:

https://community.adobe.com/t5/indesign-discussions/exploring-link-relink-function-in-javascript-and...

 

Regards,
Uwe Laubender
( Adobe Community Expert )

Translate
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
Valorous Hero ,
11 hours ago 11 hours ago
LATEST

Hi Uwe,
Thanks for pointing this out.
Although I have never used this method in my life, it sounds like intended behavior to me: change this and all other instances of the link.

It makes sense to me.

— Kasyan

Translate
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 ,
Nov 02, 2022 Nov 02, 2022

Hi Kasyan, will this script work when using Indesign Server 2022? We have an issue trying to get links to uodate that are stored in the same folder as the layout. We can print the cntent of the layout to PDF but the image links are broken and need to be relinked

Regards

Charles

Translate
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
Valorous Hero ,
Nov 02, 2022 Nov 02, 2022

Hi Charles,

No, IDS has neither dialog boxes nor selections.

Translate
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
Valorous Hero ,
Oct 03, 2017 Oct 03, 2017

Why don't you want to use the Relink to Folder feature?

04-10-2017 9-32-10.png

04-10-2017 9-33-10.png

Translate
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
Explorer ,
Dec 10, 2020 Dec 10, 2020

nothing is selected.jpgexpand imageWhy nothing is selected is showing while I have selected one image there?

Translate
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 ,
Dec 14, 2020 Dec 14, 2020

Hi abdullah,

as far as I can see from your screenshot you run the script in PhotoShop.

Kasyan's script is for InDesign documents.

 

Best,
Uwe Laubender

( ACP )

Translate
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