-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmergeMyPages.jsx
executable file
·83 lines (61 loc) · 2.3 KB
/
mergeMyPages.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
#target indesign
const ZERO = 0;
const ONE = 1;
const PAGE_TITLE = "page"
const LOOP_COUNT = 100;
const INDD_EXT = ".indd";
//reference to the Document currently active in indesign - should be master doc
allDocs = app.documents;
var numDocs = allDocs.length;
// Add new document
var tmpDoc = app.documents.add();
// Set document preferences
with(tmpDoc.documentPreferences){
pageHeight = "96p0";
pageWidth = "68p3";
pagesPerDocument = 1;
}
//Set page numbering
tmpDoc.sections[ZERO].continueNumbering = false;
tmpDoc.sections[ZERO].pageNumberStart = 1;
// Begin loop through master doc and split pages into new documents
for(var i=0; i<LOOP_COUNT/*numPages*/; i++) {
var currDocName = PAGE_TITLE + i + INDD_EXT;
currDoc = allDocs.item(currDocName);
if(currDoc != null) {
var currPath = currDoc.filePath + "/";
var currFile = File(currPath + currDoc.name);
//import styles to new doc
//char-styles
tmpDoc.importStyles(1131565940, currFile, GlobalClashResolutionStrategy.loadAllWithOverwrite);
//para-styles
tmpDoc.importStyles(1885885300, currFile, GlobalClashResolutionStrategy.loadAllWithOverwrite);
//object-styles
tmpDoc.importStyles(1332368244, currFile, GlobalClashResolutionStrategy.loadAllWithOverwrite);
// Move page to beginning of new document and remove extra page
currDoc.pages[ZERO].duplicate(LocationOptions.atEnd, tmpDoc.pages.lastItem());
currDoc.close(SaveOptions.no);
}
}
//get rid of blank page
tmpDoc.pages[ZERO].remove();
var fileName = prompt("Please enter file name:", "");
if (fileName=="") fileName = getDateName();
var filePath = Folder.selectDialog ("Please choose a Folder");
if(filePath == null) filePath = "c:";
var masterFile = File(filePath + "/" + fileName + INDD_EXT);
// Save and close new document
newDoc = tmpDoc.save(masterFile);
//newDoc.close(SaveOptions.yes);
alert("done doc merge");
function getDateName() {
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var hour = currentTime.getHours();
var minutes = currentTime.getMinutes();
if (minutes < 10) { minutes = "0" + minutes; }
var dateName = year + "-" + month + "-" + day + "_" + hour + minutes;
return dateName;
}