forked from anton-liubushkin/experimental-ps-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselectAllTextLayers.jsx
90 lines (83 loc) · 3.95 KB
/
selectAllTextLayers.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
82
83
84
85
86
87
88
89
90
// selectAllTextLayers.jsx - Adobe Photoshop Script
// Version: 0.2.0
// Requirements: Adobe Photoshop CC or higher
// Author: Anton Lyubushkin ([email protected])
// Website: http://uberplugins.cc/
// ============================================================================
// Installation:
// 1. Place script in:
// PC: C:\<Program Files>\Adobe\Adobe Photoshop <version>\Presets\Scripts\
// Mac: <hard drive>/Applications/Adobe Photoshop <version>/Presets/Scripts/
// 2. Restart Photoshop
// 3. Choose File > Scripts > selectAllTextLayers
// ============================================================================
#target photoshop
try {
var textLayers;
app.bringToFront();
selectAllLayers();
textLayers = getSelectedTextLayersIndexs();
if (textLayers.length > 0) {
selectLayersByIndex(textLayers);
} else {
deselectLayers();
}
function selectAllLayers() {
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated(charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));
desc1.putReference(charIDToTypeID('null'), ref1);
executeAction(stringIDToTypeID('selectAllLayers'), desc1, DialogModes.NO);
}
function deselectLayers() {
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated(charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));
desc1.putReference(charIDToTypeID('null'), ref1);
executeAction(stringIDToTypeID('selectNoLayers'), desc1, DialogModes.NO);
}
function getSelectedTextLayersIndexs() {
var lyrs = [];
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));
if (executeActionGet(ref).hasKey(stringIDToTypeID("targetLayers"))) {
var targetLayers = executeActionGet(ref).getList(stringIDToTypeID("targetLayers"));
for (var i = 0; i < targetLayers.count; i++) {
var ref2 = new ActionReference();
try {
activeDocument.backgroundLayer;
ref2.putIndex(charIDToTypeID('Lyr '), targetLayers.getReference(i).getIndex());
if (executeActionGet(ref2).hasKey(stringIDToTypeID('textKey'))) lyrs.push(executeActionGet(ref2).getInteger(stringIDToTypeID("itemIndex")) - 1);
} catch (o) {
ref2.putIndex(charIDToTypeID('Lyr '), targetLayers.getReference(i).getIndex() + 1);
if (executeActionGet(ref2).hasKey(stringIDToTypeID('textKey'))) lyrs.push(executeActionGet(ref2).getInteger(stringIDToTypeID("itemIndex")));
}
}
} else {
var ref2 = new ActionReference();
ref2.putProperty(charIDToTypeID("Prpr"), charIDToTypeID("ItmI"));
ref2.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
if (app.activeDocument.activeLayer.kind == LayerKind.TEXT) {
try {
activeDocument.backgroundLayer;
lyrs.push(executeActionGet(ref2).getInteger(charIDToTypeID("ItmI")) - 1);
} catch (o) {
lyrs.push(executeActionGet(ref2).getInteger(charIDToTypeID("ItmI")));
}
}
}
return lyrs
}
function selectLayersByIndex(_arrayOfIndexes) {
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
for (var i in _arrayOfIndexes) {
ref1.putIndex(charIDToTypeID('Lyr '), _arrayOfIndexes[i]);
}
desc1.putReference(charIDToTypeID('null'), ref1);
desc1.putBoolean(charIDToTypeID('MkVs'), false);
executeAction(charIDToTypeID('slct'), desc1, DialogModes.NO);
}
} catch (e) {
alert(e.line + '\n' + e);
}