-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathlinkSerializer.jsx
More file actions
69 lines (65 loc) · 2.48 KB
/
linkSerializer.jsx
File metadata and controls
69 lines (65 loc) · 2.48 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
/*
Link Serializer for InDesign ver.0.0.1
This script collects all graphics item to the selected holder and geven serialized names. Linked graphics also swapped serialized files .
All works will logged. Sreialized graphics files also have original name in XMP metadata field.
License : MTI License.
Creator : Ten A (An Adobe Community professional)
*/
linkSerializer = {
dstFolder : "~/Desktop/testFolder",
fn_prefix : "serializedFiles",
log : "~/Desktop/result.log",
ns : "http://ns.chuwa.sytes.net/idcomment/1.0/",
prefix : "ID_meta:",
f : new Object(),
read : function(prop){
if(xmpLib==undefined) var xmpLib = new ExternalObject('lib:AdobeXMPScript');
var xmpFile = new XMPFile(this.f.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ);
var xmpPackets = xmpFile.getXMP();
var xmp = new XMPMeta(xmpPackets.serialize());
alert(xmp.getProperty(this.ns, prop).toString());
},
write : function(prop, val){ //f:fileObject, val1:String, val2:String
if(xmpLib==undefined) var xmpLib = new ExternalObject('lib:AdobeXMPScript');
var xmpFile = new XMPFile(this.f.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
var xmp = xmpFile.getXMP();
var mt = new XMPMeta(xmp.serialize());
XMPMeta.registerNamespace(this.ns, this.prefix);
mt.setProperty(this.ns, prop, val);
if (xmpFile.canPutXMP(xmp)) xmpFile.putXMP(mt);
xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
},
collect : function (tgt){
var tgtFldr = Folder(this.dstFolder.toString());
if (!tgtFldr.exists) tgtFldr.create();
var tgtFile, bnds, tmp;
var num = "";
var newPath = "";
var fullPath = "";
var tg = tgt.allGraphics;
var len = tg.length;
var logFile = File(this.log);
if (logFile.open('w')){
var ts = new Date();
logFile.writeln("Start time : " + ts);
for (var i=0;i<len;i++){
if (i<10) num = "00" + i;
else if (i<100) num = "0" + i;
else num = i;
newPath = this.dstFolder+ "/" + this.fn_prefix + num + tg[i].itemLink.name.match(/\.[a-zA-Z0-9]+$/);
fullPath = tg[i].itemLink.filePath.replace(/:/g, "/");
logFile.writeln(i + "\t" + fullPath + "\t" +newPath);
tgtFile = File(tg[i].itemLink.filePath).copy(newPath);
this.f = File(newPath);
this.write("memo1", fullPath);
tmp = tg[i].parent;
tmp.place(File(newPath));
}
logFile.close();
}
}
}
//~ linkSerializer.dstFolder = "~/Desktop/collect_folder";
//~ linkSerializer.fn_prefix = "testDocument";
//~ linkSerializer.log = "~/Desktop/testResult.log";
linkSerializer.collect(app.activeDocument)