forked from Paul-Riggott/PS-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy Stack.jsx
57 lines (56 loc) · 1.96 KB
/
Copy Stack.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
#target bridge
if( BridgeTalk.appName == "bridge" ) {
copyStack = MenuElement.create("command", "Copy Stack", "at the end of submenu/Stack");
}
copyStack.onSelect = function () {
var currentFolder = Folder(app.document.presentationPath);
var selectedStacks = getselectedStacks();
if(!selectedStacks.length) return;
var copyFolder = Folder.selectDialog("Please select folder to copy stack to...",Folder(app.document.presentationPath));
if(copyFolder == null ) return;
if(decodeURI(copyFolder) == decodeURI(Folder(app.document.presentationPath))) return;
app.eventHandlers.push( { handler: onDocLoadEvent} );
var stk = getStackFiles(app.document.stacks[Number(selectedStacks[0])]);
for(var s in stk){
new Thumbnail(stk[s]).copyTo(copyFolder);
}
app.document.thumbnail = copyFolder;
function getselectedStacks(){
var stackSels = app.document.selections;
var stacksSelected = new Array();
var stks = app.document.stacks;
for(var a =0;a<stackSels.length;a++){
for(var z =0;z< stks.length;z++){
if (stks[z].thumbnails[0].spec.toString() == stackSels[a].spec.toString()){
stacksSelected.push(z);
break;
}
}
}
return stacksSelected;
};
function getStackFiles( stack ){
var files = new Array();
for( var f = 0; f<stack.thumbnails.length;f++){
files.push(stack.thumbnails[f].spec);
}
return files;
};
function createStack(){
for(var t in stk){
app.document.select(new Thumbnail(File(Folder(app.document.presentationPath) + "/" +new Thumbnail(stk[t]).spec.name)));
}
app.document.chooseMenuItem('StackGroup');
stk = new Array();
stacksSelected = new Array();
stackSels = new Array();
app.eventHandlers.pop();
app.document.thumbnail = currentFolder;
};
function onDocLoadEvent( event ){
if(event.object instanceof Document && event.type == "loaded" ){
if(decodeURI(copyFolder) == decodeURI(Folder(app.document.presentationPath))) createStack();
}
return { handled: false};
};
};