Copy link to clipboard
Copied
Hello each other
We have macOS as well as Windows in use and since InDesign does not use relative file paths, we have placed a symbolic link to the file server on Windows. But before saving the InDesign back to Windows, we want to run a script that adjusts the image paths back to the "Mac path".
Now I have a script here that almost meets my requirements. Only it also checks if the links are missed as well as updates the links. But now I don't have any links on Windows and on the macOS clients I don't want to install the script, because only one person works with Windows.
So I just wanted to create a simple script, which just stupidly and without logic rudimentary changes the path from (Attention example:) "SAMPLE" to "SMPLE". So a simple search and replace, but without relinking.
I would probably then have an InDesign server process it that way. But now I have the problem that this property is read-only.
I have also tried running the following, but to no avail:
filePath.readonly = false;
This is my script:
var doc = app.activeDocument;
var links = doc.links; //Erkennt alle Links
var counter = 0;
var PATH_FROM = "Macintosh HD";
var PATH_TO = "Windows";
for (var i = links.length -1; i >= 0; i--) {
link = links[i];
file_path = link.filePath;
new_file_path = file_path.replace(PATH_FROM, PATH_TO);
link.filePath = new_file_path;
/*
if (links[i].status == LinkStatus.LINK_MISSING) {
new_file = new File(new_file_path);
if ( new_file.exists ) {
link.relink(new_file);
link.update();
counter++;
}
else {
alert("Die Datei konnte nicht gefunden werden:\n" + new_file_path);
}
}*/
}
In InDesign I get the Error (filePath is a read-only property):
Do you have any idea? I hope you can help me.
Kind regards
Noel Bürgler
You're right Noel! Okay, here's a modified version that fits your use case I think. Let me know how you go.
- Mark
/*
Reinit Links
for Adobe Indesign 2022
by m1b
Use this when your file system has changed and current links are broken.
Set `replaceThis` and `withThis` to re-align the file paths.
This is different to Relinker because it doesn't require
modified links to exist.
*/
function main() {
reinitLinks(
// the document to relink
app.a
...
Copy link to clipboard
Copied
If the file has to be further processed then why don't you add a label with the changed path to the image container and then in IDS you can iterate all the image items and use the label to relink to the new images.
-Manan
Copy link to clipboard
Copied
Hi Manan
Thank you for the answer.
This would also be a possible way but it's not changing my problem, right?
If I would let the IDS relink all Images, it would relink to the symbolic Link, which results in missing links in macOS.
So I would like to just change the string in the filePath-Property but since it's a read-only property it's not possible.
Is there a way to change it to write too?
Thank you for the time.
Noel
Copy link to clipboard
Copied
Hi Noel, this will give you an idea of how to do it I hope.
- Mark
/*
Relinker
for Adobe Indesign 2022
by m1b
Use this when your file system has changed and current links are broken.
Set `replaceThis` and `withThis` to re-align the file paths.
*/
function main() {
relinker(
// the document
app.activeDocument,
// in each link path, replace this string or a regex
"SAMPLE",
// with this string
"SMPLE"
)
function relinker(doc, replaceThis, withThis) {
var links = doc.links,
counter = 0;
for (var i = 0; i < links.length; i++) {
// comment this out if you want to relink all links
// if (links[i].status !== LinkStatus.LINK_MISSING) continue;
// new file by replacing text within file path
var newLinkedFile = File(links[i].filePath.replace(replaceThis, withThis));
// if file exists at the new file path, relink
if (newLinkedFile.exists) {
links[i].relink(newLinkedFile);
counter++;
}
}
alert('Relinked ' + counter + ' links (out of ' + links.length + ')');
}
}
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Relinker");
Copy link to clipboard
Copied
Hey m1b
Thanks for your answer.
This script would work, if it should relink, but it shouldn't.
I just want to change the string in the filePath of the link. But it's not possible because it's read-only.
links[i].filePath = newLinkedFile;
I would like to do something like this in the for-loop. But I think it's not possible, right?
It's not possible to change the filePath-Property to write too instead of read-only, right?
Thanks for your answer.
Noel
Copy link to clipboard
Copied
You're right Noel! Okay, here's a modified version that fits your use case I think. Let me know how you go.
- Mark
/*
Reinit Links
for Adobe Indesign 2022
by m1b
Use this when your file system has changed and current links are broken.
Set `replaceThis` and `withThis` to re-align the file paths.
This is different to Relinker because it doesn't require
modified links to exist.
*/
function main() {
reinitLinks(
// the document to relink
app.activeDocument,
// in each link path, replace this string or a regex
/SAMPLE/,
// with this string
/SMPLE/
)
function reinitLinks(doc, replaceThis, withThis) {
var links = doc.links,
counter = 0;
for (var i = 0; i < links.length; i++) {
var linkURI = links[i].linkResourceURI,
newLinkedURI = linkURI.replace(replaceThis, withThis);
links[i].reinitLink(newLinkedURI);
if (linkURI != newLinkedURI)
counter++
}
alert('Reinit ' + counter + ' out of '+links.length + ' links.');
}
}
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Reinit Links");
Copy link to clipboard
Copied
Thank you very much m1b.
This is exactly what I need, tested this and it works great!!!
Again; Thank you very much for your help and have a nice day :).
Kind regards
Noel
Find more inspiration, events, and resources on the new Adobe Community
Explore Now