-
Notifications
You must be signed in to change notification settings - Fork 0
/
removeExportable.js
137 lines (112 loc) · 4.54 KB
/
removeExportable.js
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
var onRun = function(context) {
var doc = context.document,
artboard = doc.currentPage().currentArtboard(),
page = doc.currentPage(),
artboards = page.artboards(),
selection = context.selection;
var flag = ( flag === false ) ? NSOffState : NSOnState;
var checkboxArtboards = NSButton.alloc().initWithFrame( NSMakeRect( 0, 0, 300, 18 ) );
checkboxArtboards.setButtonType( NSSwitchButton );
checkboxArtboards.setTitle( 'Artboards' );
checkboxArtboards.setState( true );
var checkboxShapes = NSButton.alloc().initWithFrame( NSMakeRect( 0, 0, 300, 18 ) );
checkboxShapes.setButtonType( NSSwitchButton );
checkboxShapes.setTitle( 'Artboards' );
checkboxShapes.setState( true );
var checkboxShapes = NSButton.alloc().initWithFrame( NSMakeRect( 0, 0, 300, 18 ) );
checkboxShapes.setButtonType( NSSwitchButton );
checkboxShapes.setTitle( 'Shapes' );
checkboxShapes.setState( true );
var checkboxGroups = NSButton.alloc().initWithFrame( NSMakeRect( 0, 0, 300, 18 ) );
checkboxGroups.setButtonType( NSSwitchButton );
checkboxGroups.setTitle( 'Groups' );
checkboxGroups.setState( true );
var checkboxSymbols = NSButton.alloc().initWithFrame( NSMakeRect( 0, 0, 300, 18 ) );
checkboxSymbols.setButtonType( NSSwitchButton );
checkboxSymbols.setTitle( 'Symbols' );
checkboxSymbols.setState( true );
var checkboxText = NSButton.alloc().initWithFrame( NSMakeRect( 0, 0, 300, 18 ) );
checkboxText.setButtonType( NSSwitchButton );
checkboxText.setTitle( 'Text' );
checkboxText.setState( false );
var checkboxBitmaps = NSButton.alloc().initWithFrame( NSMakeRect( 0, 0, 300, 18 ) );
checkboxBitmaps.setButtonType( NSSwitchButton );
checkboxBitmaps.setTitle( 'Bitmaps' );
checkboxBitmaps.setState( false );
var checkboxSuffix = NSButton.alloc().initWithFrame( NSMakeRect( 0, 0, 300, 18 ) );
checkboxSuffix.setButtonType( NSSwitchButton );
checkboxSuffix.setTitle( 'Suffix ^' );
checkboxSuffix.setState( false );
var userInput = COSAlertWindow.new();
userInput.addAccessoryView(checkboxArtboards);
userInput.addAccessoryView(checkboxGroups);
userInput.addAccessoryView(checkboxShapes);
userInput.addAccessoryView(checkboxSymbols);
userInput.addAccessoryView(checkboxText);
userInput.addAccessoryView(checkboxBitmaps);
userInput.addAccessoryView(checkboxSuffix);
userInput.setMessageText('Remove Exportable');
userInput.addTextLabelWithValue("Exportable by name:");
userInput.addTextFieldWithValue("");
userInput.addButtonWithTitle('Destroy!')
userInput.addButtonWithTitle('Not today')
var responseCode = userInput.runModal();
var selectLayersOfType_inContainer = function(layerType) {
var children = page.children(),
predicate = NSPredicate.predicateWithFormat("(className == %@)", layerType),
layers = children.filteredArrayUsingPredicate(predicate);
var loop = layers.objectEnumerator(), layer;
while (layer = loop.nextObject()) {
layer.select_byExpandingSelection(true, true);
layer.exportOptions().removeAllExportFormats();
}
log(layers.count() + " " + layerType + "s selected ")
}
if (responseCode == 1000){
doc.currentPage().deselectAllLayers();
if ( checkboxArtboards.state() == true ) {
selectLayersOfType_inContainer("MSArtboardGroup");
}
if ( checkboxGroups.state() == true ) {
selectLayersOfType_inContainer("MSLayerGroup");
}
if ( checkboxShapes.state() == true ) {
selectLayersOfType_inContainer("MSShapeGroup");
}
if ( checkboxSymbols.state() == true ) {
selectLayersOfType_inContainer("MSSymbolInstance");
}
if ( checkboxText.state() == true ) {
selectLayersOfType_inContainer("MSTextLayer");
}
if ( checkboxBitmaps.state() == true ) {
selectLayersOfType_inContainer("MSBitmapLayer");
} if ( checkboxSuffix.state() == true ) {
var layers = page.children();
var matchTimes = 0;
for ( var i = 0; i < layers.count(); i++ ) {
if ( layers[i].name().match( /\^+$/gi ) ) {
matchTimes++;
layers[i].select_byExpandingSelection(true, true);
layers[i].exportOptions().addExportFormat();
}
};
log(matchTimes);
} if (userInput.viewAtIndex(7).stringValue() != "") {
var layers = page.children();
var find = new RegExp( userInput.viewAtIndex(7).stringValue() );
var matchTimes = 0;
for ( var i = 0; i < layers.count(); i++ ) {
if ( layers[i].name().match( find ) ) {
matchTimes++;
layers[i].select_byExpandingSelection(true, true);
layers[i].exportOptions().addExportFormat();
}
};
log(matchTimes + " " + userInput.viewAtIndex(7).stringValue());
}
}
if (responseCode == 1001){
doc.showMessage('Right choise) Make it manualy)')
}
}