This repository has been archived by the owner on Jul 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
relink-missing-files.jsx
115 lines (92 loc) · 2.84 KB
/
relink-missing-files.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
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
(function(thisObj){//based on RelinkLinksOfBookDocs2NewPath_inSubfolder2.js
// found on http://www.hilfdirselbst.ch/foren/Nach_fehlenden_Verkn%FCpfungen_suchen_ersetzen_-_auch_in_Unterordner_P255698.html
// if (app.books.length > 1){
// myBook = myBookSelect();
// }
// else {
// // Wiederholung des Öffnen-Dialogs so lange keine Buchdatei geöffnet ist
// while (app.books.length <1){
// var myBookFile = File.openDialog("Wähle eine Buchdatei");
// var myBook = app.open(File(myBookFile));
// }
// myBook = app.books[0];
// }
main();
function main (){
var topFolder = Folder.selectDialog ("Choose a Folder...");
if (topFolder === null){return;}
var fileandfolderAr = scanSubFolders(topFolder);
// var myDocs=myBook.bookContents;
// for (oneDoc=0; oneDoc<myBook.bookContents.length; oneDoc++){
// öffne Dokument "oneBook" des Buches
myDoc = app.activeDocument;
if(!myDoc) {
alert("please open a document");
return;
}
var missedones = 0;
myLinks = myDoc.links;
var progress_win = new Window ("palette");
var progress = progress_bar(progress_win, myLinks.length , 'Relinking images!');
for (oneLink=myLinks.length-1;oneLink>-1;oneLink--) {
myLink = myLinks[oneLink];
if(myLink.status == LinkStatus.LINK_MISSING){
myName = String(File.encode(myLink.name));
missedones++;
for (var c = 0; c < fileandfolderAr[1].length; c++){
var myNewLink = File(fileandfolderAr[1][c]+ "/" + myName);
try{
myLink.relink(myNewLink);
myLink.update();
}
catch(e){
}
}
}
progress.value++;
}
progress.parent.close();
// Dokument schließen - Sichern ohne zu fragen
// myDoc.save();
// myDoc.close(SaveOptions.yes);
// }
alert("Ready.\nRelinked "+missedones+" Files.");
}
function scanSubFolders(tFolder)
{
var sFolders = [];
var allFiles = [];
sFolders[0] = tFolder;
for (var j = 0; j < sFolders.length; j++) // loop through folders
{
var procFiles = sFolders[j].getFiles();
for (var k=0;k<procFiles.length;k++) // loop through this folder contents
{
if (procFiles[k] instanceof File) allFiles.push(procFiles[k]);
else if (procFiles[k] instanceof Folder) sFolders.push(procFiles[k]);
}
}
return [allFiles,sFolders];
}
/**
* Taken from ScriptUI by Peter Kahrel
* @usage
* var progress_win = new Window ("palette");
*
* var progress = progress_bar(progress_win, 100, 'my Progress');
*
* progress.value = i++;
* progress.parent.close();// important close it!!
*
* @param {Palette} w the palette the progress is shown on
* @param {Number} stop [description]
* @return {Progressbar} [description]
*/
function progress_bar (w, stop, labeltext) {
var txt = w.add('statictext',undefined,labeltext);
var pbar = w.add ("progressbar", undefined, 1, stop); pbar.preferredSize = [300,20];
pbar.value = 0;
w.show ();
return pbar;
}
})(this);