forked from Paul-Riggott/PS-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Clipping path names to collections.jsx
62 lines (61 loc) · 1.85 KB
/
Clipping path names to collections.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
#target bridge;
if( BridgeTalk.appName == "bridge" ) {
cpToColls = new MenuElement("command", "Clipping Path to Collections", "at the end of Tools");
}
cpToColls.onSelect = function () {
app.document.deselectAll();
var Thumbs = app.document.getSelection("psd,psb,tif,jpg,eps");
var pathList = new Array();
var pathNames = new Array();
var Name = '';
for (var z in Thumbs){
Name = getFirstClipPathName(Thumbs[z].spec);
if(Name != ''){
$.writeln("Name = " + Name + " length = " + Name.length);
pathNames.push(Name);
pathList.push([[Thumbs[z].spec],[Name]]);
}
}
pathNames = UniqueList(pathNames);
for(var t=0;t< pathNames.length;t++){
tempArray = new Array();
for(var p in pathList){
if(pathList[p][1].toString() == pathNames[t].toString()) tempArray.push(new Thumbnail(File(pathList[p][0])));
}
var colls =app.getCollections();
Found=false;
for(var k in colls){
if(colls[k].name.toString() == pathNames[t].toString()){
app.addCollectionMember(colls[k],tempArray);
Found=true;
break;
}
}
if(!Found){
var newCollection = app.createCollection(pathNames[t].toString());
app.addCollectionMember(newCollection,tempArray);
}
}
function getFirstClipPathName(file){
if(!file.exists) return;
file.open("r");
file.encoding.BINARY;
var dat = file.read();
file.close();
Text='';
if((result = dat.match(/8BIM\x0B\xB7/)) != null) {
ofs = Number(result.index+12);
Text = dat.substr(ofs+1, dat.charCodeAt(ofs));
}
return Text;
};
function UniqueList(ArrayName){
var unduped = new Object;
for (var i = 0; i < ArrayName.length; i++) {
unduped[ArrayName[i]] = ArrayName[i];
};
var uniques = new Array;for (var k in unduped) {
uniques.push(unduped[k]);}
return uniques;
};
};