-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelink_windows.jsx
39 lines (34 loc) · 1.67 KB
/
relink_windows.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#targetengine "mySession"
// Put this script in the subfolder named "Startup Scripts".
// Path: C:\Program Files\Adobe\Adobe InDesign CC 2017\Scripts
app.addEventListener( "afterOpen", checkLinks);
function checkLinks (myEvent) {
// afterOpen fires twice: once when the document opens
// and once when the window loads. So don't run the second time,
// to avoid causing an error.
// See: http://forums.adobe.com/message/5410190
if (myEvent.parent.constructor.name == "LayoutWindow") {
var windowsBaseDir = 'Z:/';
var doc = app.activeDocument,
links = doc.allGraphics;
for(var i=links.length-1;i>=0;i--)
{
var path = File(links[i].itemLink.filePath);
if(!path.exists) {
var pathAsString = links[i].itemLink.filePath.toString().substring(20);
var newPath = File(windowsBaseDir + pathAsString);
// the second path segment is sometimes production-1
// If the newPath doesn't exists we try to replace the second path segment again
if(newPath.exists){
links[i].itemLink.relink(newPath);
} else {
var pathAsString = links[i].itemLink.filePath.toString().substring(22);
var newPath = File(windowsBaseDir + pathAsString);
if(newPath.exists) {
links[i].itemLink.relink(newPath);
}
}
}
}
}
}