-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRelink Image.js
More file actions
50 lines (44 loc) · 1.5 KB
/
Relink Image.js
File metadata and controls
50 lines (44 loc) · 1.5 KB
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
40
41
42
43
44
45
46
47
48
49
50
// ----------- Relink Image ----------- //
// Relinks the base image on the current active page to a converted image saved in the same directory.
// This currently only works on the first linked image on a page.
//
// Updated: Jan 14 2021
//
// Example:
// The file linked in your INDD is a PSD. In Photoshop, you convert and flatten the image into a new .tif
// You want to relink the image in the INDD to be the new .tif
//
// Note:
// The new image needs to be in the same folder as the original image.
// Change the below file types as needed!
var fileTypes = [
{ oldType: '.psd', newType: '.tif' },
{ oldType: '.tif', newType: '.psd' },
]
function main() {
if (!isError()) {
var srcImage = app.activeDocument.layoutWindows[0].activePage.allGraphics[0];
relink(srcImage);
}
}
function isError() {
if (app.activeDocument.layoutWindows[0].activePage.allGraphics.length < 1) {
alert('Please make sure there\'s an image on the active page');
return true;
}
return false;
}
function relink(srcImage) {
var isFound = false;
for (var i = 0; i < fileTypes.length && !isFound; i++) {
var ref = fileTypes[i];
var oldPath = srcImage.itemLink.filePath;
var newPath = oldPath.replace(ref.oldType, ref.newType);
var newImage = new File(newPath);
if (oldPath.toLowerCase() !== newPath.toLowerCase() && newImage.exists) {
srcImage.itemLink.relink(newImage);
isFound = true;
}
}
}
main()