-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.jsx
More file actions
97 lines (77 loc) · 3.52 KB
/
Copy pathscript.jsx
File metadata and controls
97 lines (77 loc) · 3.52 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Bring the application to the front
app.bringToFront();
// Prompt the user to select the folder containing JPG files
var jpgFolder = Folder.selectDialog("Select JPG folder...");
// Prompt the user to select the folder containing TIF files
var tifFolder = Folder.selectDialog("Select TIF folder...");
var jpgFileList;
// Start processing the folder
processFolder();
function processFolder() {
// Get all files from the JPG folder
jpgFileList = jpgFolder.getFiles();
for (var n = 0; n < jpgFileList.length; n++) {
var theFile = jpgFileList[n].name.split(".");
var theExt = theFile[1];
// Only process files with the .jpg extension
if (theExt == "jpg") {
open(jpgFileList[n]);
// Generate corresponding TIF filename
var jpgName = jpgFileList[n].name.split(".");
var tifName = tifFolder + "/" + jpgName[0] + ".tif";
var tifFile = new File(tifName);
// Check if the matching TIF file exists
if (!tifFile.exists) {
alert("No matching TIF file!");
return;
// File is kept open for manual inspection
}
// Open the matching TIF file
open(tifFile);
// Switch focus to the first opened document (TIF)
app.activeDocument = app.documents[0];
var workPath = app.activeDocument.pathItems;
// Iterate through all paths in the TIF file
for (var p = 0; p < workPath.length; p++) {
var pathName = workPath[p].name;
// Select the current path
var idslct = charIDToTypeID("slct");
var desc218 = new ActionDescriptor();
var idnull = charIDToTypeID("null");
var ref41 = new ActionReference();
var idPath = charIDToTypeID("Path");
ref41.putName(idPath, pathName);
desc218.putReference(idnull, ref41);
executeAction(idslct, desc218, DialogModes.NO);
// Copy the path
var idcopy = charIDToTypeID("copy");
executeAction(idcopy, undefined, DialogModes.NO);
// Switch focus back to the JPG document
app.activeDocument = app.documents[1];
// Create a new path if there are multiple paths
if (workPath.length > 1) {
var idMk = charIDToTypeID("Mk ");
var desc44 = new ActionDescriptor();
var idnull = charIDToTypeID("null");
var ref13 = new ActionReference();
var idPath = charIDToTypeID("Path");
ref13.putClass(idPath);
desc44.putReference(idnull, ref13);
var idNm = charIDToTypeID("Nm ");
desc44.putString(idNm, pathName);
executeAction(idMk, desc44, DialogModes.NO);
}
// Paste the copied path
var idpast = charIDToTypeID("past");
executeAction(idpast, undefined, DialogModes.NO);
// Switch focus back to the TIF document
app.activeDocument = app.documents[0];
}
// Close TIF without saving
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
// Save JPG and close without further changes
app.activeDocument.save();
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
}
}