Relink missing links with script
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?
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?
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
.
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();
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.