forked from avialxee/photoshop-jsx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autotype.jsx
81 lines (60 loc) · 2.17 KB
/
autotype.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
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
// written by @avialxee
// MIT License
#target photoshop
#include json2.js // json to js parser
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
var theName = myDocument.name.match(/(.*)\.[^\.]+$/)[1];
var thePath = myDocument.path;
var outpath = thePath+'/output/';
psdOpts = new PhotoshopSaveOptions();
psdOpts.embedColorProfile = true;
psdOpts.alphaChannels = true;
psdOpts.layers = true;
psdOpts.spotColors = true;
var obj = loadInput('inputs.json')
function loadInput(relpath){
var input = new File($.fileName);
var jsoninput = new File(input.path + '/' + relpath);
jsoninput.open('r');
var name = jsoninput.read();
jsoninput.close();
return JSON.parse(name);
}
for (var i in obj.name) {
var TitleGroup = myDocument.layerSets.getByName('baseImage');
var TitleGroup2 = myDocument.layerSets.getByName('text');
var thNamer = obj.name[i];
VolLayer = TitleGroup2.artLayers.getByName('participantName');
myDocument.activeLayer = VolLayer;
//var theFiles = ppath + thNamer + '.tif';
if (thNamer) {
//VolLayer = replaceContents(theFiles);
VolLayer.textItem.contents = thNamer;
saveJPEG(thNamer);
alert("saved Jpeg");
myDocument.saveAs((new File(outpath+ thNamer + "_" + ".psd")), psdOpts, true);
}
}
};
function getFiles(theFile) {
if (theFile.name.match(/\.(psd|tif)$/i)) {
return true
};
};
function replaceContents(newFile) {
var idplacedLayerReplaceContents = stringIDToTypeID("placedLayerReplaceContents");
var desc3 = new ActionDescriptor();
var idnull = charIDToTypeID("null");
desc3.putPath(idnull, new File(theFiles));
var idPgNm = charIDToTypeID("PgNm");
desc3.putInteger(idPgNm, 1);
executeAction(idplacedLayerReplaceContents, desc3, DialogModes.NO);
};
function saveJPEG(name) {
var doc = app.activeDocument;
var file = new File(outpath + name + '.Jpg');
var opts = new JPEGSaveOptions();
opts.quality = 10;
doc.saveAs(file, opts, true);
}