-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom_export_import.jsx
3709 lines (3495 loc) · 200 KB
/
custom_export_import.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#target bridge
if (BridgeTalk.appName == 'bridge')
/*
Terms and Conditions of Use:
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
{ // brace 1 open
// menu text
var mdMenu = "Metadata_Deluxe"; // computer friendly. filenames - don't use spaces, use _
var mdMenuLabel = mdMenu.split("_").join(" ") // human friendly, replace _ with space
var mdCeI = "Custom Export-Import";
var mdCeIVersion = "1.0.5";
var mdCeICodeDate = "2022-11-08";
// added .hide() to all palette .close(), fixed Mapping display; changed export file name to current foler+dateYMD; replaced type with xmpType; replaced header with label
// changed field arr to new style; using indexOf to remove prefix from XMP_Property for read/write; fixed fieldList.add to use dropdown field text
// added new build properties; added populate fields list based on lastViewedHeadersPanel; register namespaces from lastViewedHeadersPanel
// added try catch to loadCustom.but1.onClick
// added originalLastViewedHeadersPanel and originalCustomFileText so original values can be restored when custom fields window Cancel is clicked
// added set load standard schema dropdown to "" when Clear is clicked
// moved var exportSaveLocation within export function
// added var customFileArr = customFileText.split("\n") to import function
// changed the way images folder location is determined and displayed - added expImp_thumbSelected as eventHandler, delete this handler on window close
// added basicFieldsArr; added; if(textFile[textFile.length-1].length == 0) to if "Match on filename" is selected check that column B has a value, else show alert
// added to loadSchema.dd1.onChange: if(schemaArr[Lls].Schema_Field != "File-Name") to avoid double File-Name properties
// changed fieldsArr item Field: to Schema_Field:
// fieldsWindow.close(); // causes fieldsWindow to not re-open after Cancel, so MOVED to mainWindow.onClose()
// changed "Add" button function so new field is inserted below currently selected filed in the list
// function saveCustomHeaders(){ - added mainWindow.enabled = true;
// saveCustomHeaders(){ - moved change custom fields label on main window within if(enterCustomNameName.text){
// var pos = 0 - added condition based on number of items in list
// 2019-12-01 addBtn.onClick=function(){ - added var itemSelectedIndex = fieldList.items.length-1; set selected item to new added field
// experimenting with multi-column fields fieldList. See addMoveDelteBtns.but1.onClick
// changed pluginPrefs to mdMenu
// changed var fieldList2 to var fieldList
// testing github
// changed import currentPath to use any thumb, not just image file
// changed export complete text to reflect 0 files exported
// Export entire folder was failing - changed FROM if (testFileExtension(Thumb[L2].spec) == false) TO if (testFileExtension(Thumb[L2]) == false)
// changed import paths to use .spec.fsName search for PATH EDIT. Custom list UNDEFINED on open now - need to fix - check lastViewedHeadersPanel SEE app.document.presentationPath.split(slash).join("/")+"/";
// added appDataPlgnSet.encoding = "UTF8"; to write CJK to prefs text file
// line 2004 changed var currentFolderPath
// EXPORT & IMPORT, changed to .presentationPath - var currentFolderPath = app.document.presentationPath;// PATH EDIT
// IMPORT, changed var selectedFolder = Folder(currentFolderPath) to var selectedFolder = Folder(currentFolder)
// IMPORT changed if (testFileExtension(Thumb[L2]) == false) // failing on selectedThumnails TO if (testFileExtension(singleFile) == false)
// EXPORT added condition "if entire folder is selected" if "Include subfolders" is not checked, only read the files in the selected folder TODO: do I need to add anything when selected thumbs is selected? - progress bar? allFiles no longer needed?
// Changed "Fields: " to "Current Fields: "
// EXPORT and IMPORT function getSubFolders: added condition && myFile.getFiles().length > 0 because empty sub-folders caused the script to stall
// Customize fields: if no custom fields definedm then exportBtn.enabled = false, else exportBtn.enabled = true
// all fields to fieldList.onDoubleClick window
// added enterCustomNameName.text = lastViewedHeadersPanel;
// added editFieldsPrompt window (if no fields list exists, open a new window to prompt user to edit the fields list)
// added disable loadCustom.but1 if Current Fileds: UNDEFINED (enable after saving custom fields)
// added separate headers group to fieldList for readability
// added .active = true; every time a window is returned to (otherwise it would not be active on a Mac)
// adjusted UI dimensions for Mac
// 2020-10-27 changed var splicePathIndex = allFiles[L2].fsName.toString().lastIndexOf (slash);was ("\\")
// 2020-10-30 changed import files path section; updated help tips; added currentFields to export .txt filename
// 2020-11-02 function toggleImportBtn(){ // removed importImageFolderOK == true && ; dataSourceFileAlert changed text color to red
// 2020-11-17 removed var xmpLib = new ExternalObject("lib:" + pathToXMPLib );not needed
// version 1.0.2
// 2021-02-12: added ai and xd to function testFileExtension(file)
// 2021-02-13 changed to xmpLib == undefined to ExternalObject.AdobeXMPScript == undefined; simplified Load the XMP Script library; changed to // FASTER READ/WRITE read and write methods; removed ImportInst.templateBtn and changed ImportInst.text
// version 1.0.3
// 2021-02-16" reduced size of cutomization window to fit 1366 x 768 screen resolution
// 2021-02-22: added try/catch to export folder and filename functions
// 2021-02-24: changed reda/write from FASTER READ/WRITE to XMPConst.OPEN_FOR_READ and XMPConst.OPEN_FOR_UPDATE to avoid crashing (not sure why it crashed on FASTER, but it did)
// 2021-05-13: moving text to variables
// 2021-07-29: IMPORT: moved var currentFolderPath = app.document.presentationPath; outside of old // get currentPath if loop
// 2022-03-12: added IPTC-Alt Text (Accessibility) and IPTC-Extended Description (Accessibility) to iptcFieldsArr
// 2022-07-09: IMPORT: for 'langAlt' /properties, get the x-default value
// 2022-09-08: because user reported windows was too small cutting off content, changed all dimensions to minimumSizs and maximumSize
// version 1.0.4
// 2022-11-06: added Copyright Status to basicFieldsArr; added test that file is .txt to testTextFileExists; changed fieldList column labels to show:true (otherwise column widths not working); changed button and spacing for Bridge 2023; changed Import propPass to reste for each thumb loop; changed Import Set white label to only set if the thumb had metadata changes; changed delete prop method when no text value for import when XMP_Type == 'text'; changed inputs.addEventListener addMoveDelteBtns.but4.enabled = false; changed Add button to always add at end of list because of invalid vector subscript error; addMoveDelteBtns.but4.onClick added addMoveDelteBtns enabled = false; disabled move up/down buttons in Bridge 2023 v 13.0.0.562 because those functions cause an error; fixed double if (writeOptions.overwriteRb.value == true) which prevented Write only to empty fields; write to 'text': moved parseCSV(textFileValue[index]) above (writeOptions.overwriteRb.value == true)
//Create a menu option within Adobe Bridge
var findMdMenu = MenuElement.find (mdMenu);
if (findMdMenu == null){
var addMdMenu = new MenuElement ('menu', mdMenuLabel, 'before Help', mdMenu);
}
var mdMenuExpImp = new MenuElement ('command', mdCeI, 'at the beginning of '+mdMenu);
mdMenuExpImp.onSelect = function()
{ // brace 2 open
// Load the XMP Script library
if ( ExternalObject.AdobeXMPScript == undefined ) {
ExternalObject.AdobeXMPScript = new ExternalObject( "lib:AdobeXMPScript" );
}
// get Bridge version number for compatibility warning. look for brVersionNum for functions disabled in Bridge 2023 (v. 13)
var brVersionNum = app.version.toString().split ('.')[0]; // just the main version, not variants
/* array of prettier Bridge version labels based on app.version number
var brVersionLabel = ""
var brVersionArr = [{num:3, lbl:"Bridge CS4"},{num:4, lbl:"Bridge CS5"},{num:5, lbl:"Bridge CS6"},{num:6, lbl:"Bridge CC 2015"},{num:7, lbl:"Bridge CC 2017"},{num:8, lbl:"Bridge CC 2018"},{num:9, lbl:"Bridge CC 2019"},{num:10, lbl:"Bridge 2020"},{num:11, lbl:"Bridge 2021"},{num:12, lbl:"Bridge 2022"},{num:13, lbl:"Bridge 2023"}]
for (var La = 0; La < brVersionArr.length; La++){
if(brVersionArr[La].num == brVersionNum){
brVersionLabel = brVersionArr[La].lbl.split(" ").join("%20")
}
}
*/
// TODO different way to identify user prefs folder?
/*
var userF = Folder.userData; //User library
var scriptf = File($.fileName); //script name (only works when you run from StartupScripts, not debuggung in ESTK))
var scriptfo = scriptf.parent; //parent folder of script
var loc = scriptfo + '/images/'; //images folder
var UPprefsPath = ''; //path to preferences file
var UPprefsVersion = '2.0.9'; //always increment with preference file changes
*/
// variables used throughout
// Don't change these, you will break several functionns ////////
var appDataFwdSlash = Folder.userData;
var plgnPrefs = "/"+mdMenu+"_Import_Export";
var plgnSet = "/settings.txt";
var hardDriveCheck = hardDrive;
var plgnOpt = "/Options";
var exportChoice = "folder";
var plgnHeaders = "/Import-Export_Fields";
var enteredCustomName = "Custom_Fields_01";
/////////////////////////////////////////////////////////////////////////////////////////////////////////
var dateTime = new XMPDateTime(new Date()); // today's date and time
var dateYMD = dateTime.toString().slice(0, -19);
var plgnName = ""+mdMenuLabel+" "+mdCeI;
var originalLastViewedHeadersPanel = "";
var lastViewedHeadersPanel = "";
var loadedDefineHeadersText = "";
var originalCustomFileText = "";
var customFileText = "{Schema_Field:'File-Name', Label:'File Name', Namespace:'file', XMP_Property:'file', XMP_Type:'file'}";
var fieldsArr = [];// array of objects for export and import functions. this is populated by user saved text file or set by the user in the build properties window
var arrowLeft = "←";
var arrowRight = "→";
// buttons
var exportWhichFieldsArrRbTxt = "Selected thumbnail(s) in Bridge";
var exportWhichFolderRbTxt = "Entire folder";
var exportWhichSubfoldersCbTxt = "include subfolders";
var exportOptionsDatesCbTxt = "prepend Image dates with '_'";
var exportOptionsLfCbTxt = "Remove line breaks";
var exportBtnTxt = "Export";
// text and labels
var editFieldsPromptSt1Text = "There are no fields defined for Export/Import\n\nBegin by customizing the Fields List";
var fieldsTxtTxt = "Current Fields: ";
var setHeadersTxt= "Edit Fields";
var exportTxtLow = "export";
var exportTxtUp = "EXPORT";
var importTxtLow = "import";
var importTxtUp = "IMPORT";
var exportPanelTxt = "Export Metadata";
var exportWhichTxt = "Files to export";
// tool tips
var addLabelTT =
"When selected, each image that has metadata successfully imported will have its label set to: '"+mdMenuLabel+" metadata imported' and the label color will be changed to white.\n"+
"Warning: Existing labels will be lost.";
var appendDataTT =
"Applies the tab-delimited import metadata\n"+
"where no metadata value or property currently\n"+
"exists in the file.\n"+
" • Does not overwrite existing data.\n"+
" • Data will only be imported to blank fields."
var clickInstrucTT = "Click for instructions";
var createTemplateTT =
"Creates a text file which, when opened in Excel, contains the proper column field names for the "+mdMenuLabel+" import function.\nYou can then paste your own data in the appropriate columns for import.";
var dateWhyTT =
"This is useful if you will be importing the metadata to Excel.\n\n"+
"XMP Date values must use the YYYY/MM/DD format. Adding a '_' character at the beginning of the Date will prevent Excel from automatically changing it to a format XMP cannot understand.\n\n"+
"The '_' character will be removed when you import the data back into the image file(s).";
var exportWhichTT = "Change folder using Bridge navigation";
var fieldLabelsLbl1TT = "Pre-defined schema field name (not editable)";
var fieldLabelsLbl2TT = "Do not change for pre-defined schemas, set your own for custom property";
var fieldLabelsLbl3TT = "The label you want to use for the field";
var fieldLabelsLbl4TT = "namespace URL, EXAMPLE: http:https://purl.org/dc/elements/1.1/";
var fieldLabelsLbl5TT = "namespace prefix:property name, EXAMPLE: dc:title";
var fieldLabelsLbl6TT = "XMP property type. Consult schema documentation, or set for your custom property";
var fieldsTxtTT = "List of fields to be exported/imported";
var IgnoreExtCbTT =
"When selected, metadata will be imported to all matching media with matching file names regardless of the file extension.\n"+
"This allows you to import matching metadata to all versions of the same media file, e.g., .tif, .jpg. .png.";
var imageFolderBrowseTT = "Locate the path to your folder of images";
var imageFolderPathTT = "Folder containing files";
var imageLocTT = "Change folder using Bridge navigation";
var lineFeedWhyTT =
"This is useful if you will be importing the metadata to Excel.\n\n"+
"When selected, line breaks (line feed and carriage return) will be replaced by a semi-colon and a space ('; ').\n\n"+
"When not selected, line breaks will be retained but converted to plain text place holders ('LF'), ('CR') so that they are not changed by Excel. When the data is imported back to an image, the codes will be changed to the proper XMP encoding.";
var loadCustomBut1TT = "Select and load a saved custom field list";
var loadCustomBut2TT = "Open folder containing your custom field lists so you can edit or delete them";
var loadCustomEt1TT = "List of fields to be exported/imported";
var replaceDataTT =
"Completely replaces any existing metadata\n"+
"in the image file(s) with the metadata in the\n"+
"tab-delimited import file.\n"+
" • Overwrites all fields except camera and\n"+
" software fields.";
var setHeadersTT = "Edit the list of fields to be exported/imported";
var textFileBrowseTT = "Locate the path to your .txt file";
var textFilePathTT = "Tab-delimited text file (.txt) of metadata to be imported\n\nClick 'Browse' to locate file"
// instructions
var exportOptInstTxt = "Export Options";
var exportOptInstTextTxt =
"Export Options\n\n"+
"Option 1: prepend Image dates with '_'\n"+
" This is useful if you will be importing the metadata to Excel.\n"+
" XMP Date values must use the YYYY/MM/DD format. Adding a '_' character at the beginning of\n"+
" the Date will prevent Excel from automatically changing it to a format XMP cannot understand.\n"+
" (if your system is set up for another format, that will bereflected in the way Excel displays dates)\n"+
" The '_' character will be removed when you import the data back into the image file(s).\n\n"+
"Option 2: Remove line breaks\n"+
" This is useful if you will be importing the metadata to Excel.\n"+
" When selected, line breaks (line feed and carriage return) will be replaced by a semi-colon and a space ('; ').\n"+
" When not selected, line breaks will be retained but converted to plain text place holders ('LF'), ('CR') so\n"+
" that they are not changed by Excel. When the data is imported back to an image, the codes will be\n"+
" changed to the proper XMP encoding."
var ExportInstTxt = "Export Instructions";
var ExportInstTextTxt =
" Choose which files to export\n" +
" From selected files only\n" +
" 1. Select file(s) in Adobe Bridge\n"+
" 2. Under ‘Images’, choose 'Selected thumbnails in Bridge'\n" +
" 3. Select desired export options (see below)'\n" +
" 4. click 'Export'\n" +
" 5. Choose name and location for your export file (.txt format)'\n" +
" 6. Saven\n" +
" From all image files in a folder\n" +
" 1. Select 'Entire folder'\n" +
" 2. Use 'browse' to select folder you wish to use\n" +
" 3. If you want to export images in all subfolders check the box 'include subfolders'\n" +
" 4. Select desired export options (see below)\n" +
" 5. Click 'Export'\n" +
" 6. Choose name and location for your export file (.txt format)\n" +
" 7. Save\n\n" +
" After export is complete\n" +
" 1. Open your .txt file in a spreadsheet using tab delimiters.\n" +
" 2. Because the .txt file is created as UTF-8, it is best to use the Excel import text wizard to retain\n"+
" proper character encoding, e.g. ©, 작, ü\n"+
" a. Use import option and select a .txt file to import\n" +
" b. Text Import Wizard\n" +
" i. File origin = 65001- Unicode (UTF-8)\n" +
" ii. Delimited = Tab\n" +
" iii. Finish\n" +
" 3. The first row will contain the field names.\n"+
" Each row below that will contain metadata for a single exported file."
// If the current file system is Windows, create directory location variables
if (Folder.fs == 'Windows'){
var spot = "•";
var hardDrive = "C:\\";
var appDataPlgnSetBkSlash = Folder (File.decode (Folder.userData)).toString().split ("/").join ("\\"); // User preferences file
}
// If the current file system is Mac, create directory location variables
else{
var spot = "•";
// var userData = "//";
var hardDrive = "//";
var appDataPlgnSetBkSlash = Folder (File.decode (Folder.userData)).toString();
while (appDataPlgnSetBkSlash.split ("/.").length > 1) var appDataPlgnSetBkSlash = appDataPlgnSetBkSlash.split ("/.").join ("/");
while (appDataPlgnSetBkSlash.split ("./").length > 1) var appDataPlgnSetBkSlash = appDataPlgnSetBkSlash.split ("./").join ("/");
var pathFirstChar = "/";
if (appDataPlgnSetBkSlash.substring (0,1) == "~") var pathFirstChar = "~";
var appDataPlgnSetBkSlash = appDataPlgnSetBkSlash.split ("~").join ("");
while (appDataPlgnSetBkSlash.split ("//").length > 1) var appDataPlgnSetBkSlash = appDataPlgnSetBkSlash.split ("//").join ("/");
}
// set slach charcter (for directory and file path) based on operating system TODO: test on Mac
if (Folder.fs == "Windows"){
var slash = "\\";
}
else{
var slash = "/";
}
// desktop
if (Folder.fs == "Windows"){
var desktop = "~\\Desktop\\";
}
else{
var desktop = "~/Desktop/";
}
/*
// default location for export text file
// NOTE: first instance of file - folder in a folder is not useful
var currentPath = app.document.visibleThumbnails[0].spec.toString()
var currentPathToArray = app.document.visibleThumbnails[0].spec.toString().split("/")
var currentFolder = currentPathToArray[currentPathToArray.length-2].split("%20").join("_")
if (Folder.fs == "Windows"){
// var exportSaveLocation = desktop+"embedded_metadata_"+dateYMD+".txt";
var exportSaveLocation = "~\\Desktop\\"+currentFolder+"_METADATA_"+dateYMD+".txt"; // dateTime OR dateYMD
// var exportSaveLocation = currentPath+"_METADATA_"+dateYMD+".txt"; // let user select save location, filename based on current folder
}
else{
// var exportSaveLocation = desktop+"embedded_metadata_"+dateYMD+".txt";
var exportSaveLocation = "~/Desktop/"+currentFolder+"_METADATA_"+dateYMD+".txt"; // dateTime OR dateYMD
// var exportSaveLocation = currentFolder+"_METADATA_"+dateYMD+".txt"; // let user select save location, filename based on current folder
}
// var currentPathSaveFile = currentPath+"_"+dateYMD+".txt";save to same folder as images being exported, filename based on current folder
*/
var mode = "export"
// size variables for UI objects
var hidden = [0,0];
var panelSize = [700,600];
// option variables
var exportImageFolderOK = false;
var exportTextFolderOK = false;
var exportTextFileOK = false;
var importTextFolderOK = false;
var importTextFileOK = false;
// if it doesn't already exist, create folder: C:\Users\[user name]\AppData\Roaming\IPTC_CH_Import_Export\Options
if (Folder (appDataFwdSlash + plgnPrefs).exists == false){
new Folder (appDataFwdSlash + plgnPrefs).create();
//removed code here that writes 'appDataFwdSlash' to desktop if writing to appDataFwdSlash failed
}
// if it doesn't already exist, create folder 'userData/"+mdMenu+"_Import_Export/Options'
if (Folder (appDataFwdSlash + plgnPrefs + plgnOpt).exists == false) new Folder (appDataFwdSlash + plgnPrefs + plgnOpt).create();
//////////////////////////////////////////////////////////////// BEGINNING OF MAIN UI WINDOW ////////////////////////////////////////////////////////////////
// Create the main dialog box
var mainWindow = new Window('palette', mdMenuLabel+" "+mdCeI+" (v"+mdCeIVersion+")");
mainWindow.spacing = 5;
{ // main UI window - brace 1 open
// header
settingsGroup = mainWindow.add('group', undefined, undefined)
//settingsGroup.preferredSize = [720, 20]
settingsGroup.alignment='left';
fieldsTxt = settingsGroup.add('statictext', undefined, fieldsTxtTxt+lastViewedHeadersPanel);
fieldsTxt.minimumSize = [300,25];
fieldsTxt.maximumSize = [300,25];
//fieldsTxt.justify = "center";
fieldsTxt.graphics.font = ScriptUI.newFont ('Arial', 'BOLD', 16);
fieldsTxt.graphics.foregroundColor = fieldsTxt.graphics.newPen (mainWindow.graphics.PenType.SOLID_COLOR, [1,0.58,0], 1);
fieldsTxt.helpTip = fieldsTxtTT; // name of the currently loaded field list
setHeaders = settingsGroup.add('button', undefined, setHeadersTxt)
setHeaders.minimumSize = [100,25];
setHeaders.maximumSize = [100,25];
// setHeaders.alignment = 'left';
setHeaders.helpTip = setHeadersTT;
setHeaders.onClick = function(){
mainWindow.enabled = false;
fieldsWindow.show();
fieldsWindow.active = true;
originalLastViewedHeadersPanel = lastViewedHeadersPanel;
originalCustomFileText = customFileText;
}
navGroup = mainWindow.add('group', undefined, undefined)
navGroup.margins = [0,10,0,0]
navExportBtn = navGroup.add('radiobutton', undefined, arrowLeft+exportTxtUp+arrowRight)
navExportBtn.minimumSize = [150,20];
navExportBtn.maximumSize = [150,20];
navExportBtn.value = true
navExportBtn.onClick = function(){mode = "export"; toggleNav();}
navImportBtn = navGroup.add('radiobutton', undefined, importTxtLow)
navImportBtn.minimumSize = [150,20];
navImportBtn.maximumSize = [150,20];
navImportBtn.onClick = function(){mode = "import"; toggleNav();}
mainWindow.row = mainWindow.add( 'group' );
mainWindow.row.orientation = 'row';
mainWindow.row.spacing = 0;
// Export section
exportPanel = mainWindow.row.add('panel', undefined, exportPanelTxt);
exportPanel.spacing = 2;
exportPanel.margins = 3;
exportPanel.alignChildren = 'center';
exportPanel.minimumSize = [675, undefined];
exportPanel.maximumSize = [675, undefined];
// Export Instructions button
exportInstButton = exportPanel.add('button', undefined, "?");
exportInstButton.minimumSize = [32,25];
exportInstButton.maximumSize = [32,25];
exportInstButton.alignment = 'right';
exportInstButton.helpTip = clickInstrucTT;
exportInstButton.onClick = showExportInst;
// Select which files to export
var selections = app.document.selections;
var folder = app.document.visibleThumbnails;
exportWhich = exportPanel.add('panel', undefined, exportWhichTxt);
exportWhich.alignChildren = 'left';
exportWhich.spacing = 2;
exportWhich.margins = 5;
// Spacer
spacer1 = exportWhich.add( 'group' );
spacer1.minimumSize = [10,5];
exportWhich.fieldsArrRb = exportWhich.add('radiobutton', undefined, exportWhichFieldsArrRbTxt);
exportWhich.fieldsArrRb.onClick = function(){
exportChoice = "thumbs";
toggleExportWhich();
}
exportWhich.folderRb = exportWhich.add('radiobutton', undefined, exportWhichFolderRbTxt);
exportWhich.folderRb.value = true;
exportWhich.folderRb.onClick = function(){
exportChoice = "folder";
toggleExportWhich();
}
exportWhich.subfoldersGr = exportWhich.add('group');
exportWhich.subfoldersGr.orientation = 'column';
exportWhich.subfoldersGr.alignChildren = 'left';
exportWhich.subfoldersGr.indent = 100;
exportWhich.subfoldersGr.spacing = 0;
exportWhich.folderEt = exportWhich.subfoldersGr.add('statictext', undefined, "");
exportWhich.folderEt.minimumSize = [550,25];
exportWhich.folderEt.maximumSize = [550,25];
exportWhich.folderEt.helpTip = imageFolderPathTT;
exportWhich.subfoldersCb = exportWhich.subfoldersGr.add('checkbox', undefined, exportWhichSubfoldersCbTxt);
// Panel for options
exportOptionsGrp = exportPanel.add('group', undefined, undefined);
exportOptions = exportOptionsGrp.add('panel', undefined, 'Options');
exportOptions.alignChildren = 'left';
exportOptions.spacing = 2;
exportOptions.dates = exportOptions.add( 'group' );
exportOptions.dates.orientation = 'row';
exportOptions.datesCb = exportOptions.dates.add('checkbox', undefined, exportOptionsDatesCbTxt);
exportOptions.datesCb.value = true;
exportOptions.datesCb.minimumSize = [200, undefined];
// exportOptions.datesCb.helpTip = dateWhyTT;
exportOptionsLf = exportOptions.add( 'group' );
exportOptionsLf.orientation = 'row';
exportOptionsLfCb = exportOptionsLf.add('checkbox', undefined, exportOptionsLfCbTxt);
exportOptionsLfCb.value = true;
exportOptionsLfCb.minimumSize = [200, undefined];
// exportOptionsLfCb.helpTip = lineFeedWhyTT;
// Export Options Instructions button
exportOptionsButton = exportOptionsGrp.add('button', undefined, "?");
exportOptionsButton.alignment = 'right';
exportOptionsButton.minimumSize = [32,25];
exportOptionsButton.maximumSize = [32,25];
exportOptionsButton.helpTip = clickInstrucTT;
exportOptionsButton.onClick = showExportOptInst
exportBtn = exportPanel.add('button', undefined, exportBtnTxt);
exportBtn.minimumSize = [150,40];
exportBtn.maximumSize = [150,40];
exportBtn.enabled = false;
exportBtn.onClick = exportToFile;
// check to see if the folder of images specified exists
function testExportImagesFolder(){
var selectedFolder = Folder(exportWhich.folderEt.text.split(" ").join("%20"));
if (exportWhich.folderEt.text && selectedFolder.exists == false){
exportImageFolderOK = false;
}
else if (exportWhich.folderEt.text && selectedFolder.exists == true){
exportImageFolderOK = true;
}
toggleExportBtn();
}
function toggleExportBtn(){
if (exportImageFolderOK == true){
exportBtn.enabled = true;
}
else{
exportBtn.enabled = false;
}
}
// test to see if the paths entered by user exist
exportWhich.folderEt.addEventListener('changing',function(){testExportImagesFolder()});
// If user selects export to "Entire folder", show folder path box, otherwise hide it
function toggleExportWhich(){
if (exportChoice == "thumbs"){
exportWhich.subfoldersGr.visible = false;
exportBtn.enabled = true;
}
else{
exportWhich.subfoldersGr.visible = true;
toggleExportBtn;
}
}
// instruction windows
function showExportInst(){
var ExportInst = new Window('palette', ExportInstTxt);
ExportInstText = ExportInst.add('statictext', undefined, ExportInstTextTxt, {multiline:true});
if (Folder.fs == "Windows"){
ExportInstText.minimumSize = [600,450];
ExportInstText.maximumSize = [600,450];
}
else{
ExportInstText.minimumSize = [700,550];
ExportInstText.maximumSize = [700,550];
}
ExportInst.optionsBtn = ExportInst.add('button', undefined, 'Export options');
ExportInst.optionsBtn.minimumSize = [120,25];
ExportInst.optionsBtn.maximumSize = [120,25];
ExportInst.optionsBtn.onClick = function(){showExportOptInst()}
ExportInst.optionsBtn.alignment = 'left'
ExportInst.cancelBtn = ExportInst.add('button', undefined, 'Close');
ExportInst.cancelBtn.onClick = function(){
ExportInst.hide();
ExportInst.close();
mainWindow.active = true;
}
ExportInst.show();
ExportInst.active = true;
}
function showExportOptInst(){
var exportOptInst = new Window('palette', exportOptInstTxt);
exportOptInstText = exportOptInst.add('statictext', undefined, exportOptInstTextTxt, {multiline:true});
if (Folder.fs == "Windows"){
exportOptInstText.minimumSize = [650,230];
exportOptInstText.maximumSize = [650,230];
}
else{
exportOptInstText.minimumSize = [700,280];
exportOptInstText.maximumSize = [700,280];
}
exportOptInst.cancelBtn = exportOptInst.add('button', undefined, 'Close');
exportOptInst.cancelBtn.onClick = function(){
exportOptInst.hide();
exportOptInst.close();
}
exportOptInst.show();
exportOptInst.active = true;
}
// Panel for Import section
importPanel = mainWindow.row.add('panel', undefined, "Import Metadata");
importPanel.spacing = 3;
importPanel.margins = 3;
importPanel.alignChildren = 'center';
importPanel.minimumSize = hidden
importPanel.maximumSize = hidden
// Info button
importInstButton = importPanel.add('button', undefined, '?');
importInstButton.minimumSize = [32,25];
importInstButton.maximumSize = [32,25];
importInstButton.alignment = 'right';
importInstButton.helpTip = clickInstrucTT;
importInstButton.onClick = function showImportInst(){
var ImportInst = new Window('palette', "Import Instructions");
ImportInst.body = ImportInst.add('group');
ImportInst.body.orientation = 'column';
ImportInst.body.spacing = 5;
var text1 =
"This script imports data from a tab delimited text file into image files with matching filenames.\n\n" +
" If you have already exported metadata and edited it in Excel and want to import it back in:\n" +
" 1. Select the folder containing the target images\n" +
" a. If you have nested folders, check 'include subfolders'\n" +
" 2. Select the text file to be imported\n" +
" a. Click 'Import' and cross your fingers\n\n" +
" If you are starting with external metadata (from a database, etc.)\n" +
" First, you need a properly formatted spreadsheet.\n"+
" Open the Export window and export the files you want to work on.\n" +
" Import this text file into a spreadsheet.\n" +
" This will give you the file names and columns to enter your metadata into."
" Look for this new file on your desktop\n" +
" 1. Open the text file in Excel\n" +
" 2. Add data to the appropriate columns\n" +
" 3. Save as a tab-delimited text (.txt) file\n" +
" a. Format as Unicode UTF-8 or 16\n\n"
var text2 =
" To import data into image files:\n" +
" 1. Select the folder containing the target images\n" +
" a. If you have nested folders, check 'include subfolders'\n" +
" 2. Select the text file to be imported\n" +
" 3. Click 'Import' and cross your fingers";
ImportInst.text1 = ImportInst.body.add('statictext', undefined, text1, {multiline:true});
if (Folder.fs == "Windows"){
ImportInst.text1.minimumSize = [540,200];
ImportInst.text1.maximumSize = [540,200];
}
else{
ImportInst.text1.minimumSize = [620,240];
ImportInst.text1.maximumSize = [620,240];
}
/* not used
ImportInst.templateBtn = ImportInst.body.add ('button', undefined, "Create "+mdMenu+"_import_default template.txt");
ImportInst.templateBtn.helpTip = createTemplateTT;
ImportInst.templateBtn.alignment = 'left';
ImportInst.templateBtn.indent = 50;
ImportInst.templateBtn.onClick = createTemplate;
*/
ImportInst.text2 = ImportInst.body.add('statictext', undefined, text2, {multiline:true});
if (Folder.fs == "Windows"){
ImportInst.text2.minimumSize = [540,110];
ImportInst.text2.maximumSize = [540,110];
}
else{
ImportInst.text2.minimumSize = [620,130];
ImportInst.text2.maximumSize = [620,130];
}
ImportInst.optionsBtn = ImportInst.add('button', undefined, 'Import options');
ImportInst.optionsBtn.minimumSize = [120,25];
ImportInst.optionsBtn.maximumSize = [120,25];
ImportInst.optionsBtn.onClick = function(){showImportOptInst();}
ImportInst.optionsBtn.alignment = 'left'
ImportInst.cancelBtn = ImportInst.add('button', undefined, 'Close');
ImportInst.cancelBtn.onClick = function(){
ImportInst.hide();
ImportInst.close();
mainWindow.active = true;
}
ImportInst.show();
ImportInst.active = true;
}
function showImportOptInst(){
var importOptInst = new Window('palette', "Import Options");
var body =
"Import Options\n\n"+
"Option 1: Ignore file extensions\n"+
" When selected, metadata will be imported to all matching media with matching file names regardless\n"+
" of the file extension.\n"+
" This allows you to import matching metadata to all versions of the same media file, e.g., .tif, .jpg. .png.\n\n"+
"Option 2: Set Thumbnail Label\n"+
" When selected, each image that has metadata successfully imported will have its label set to:\n"+
" 'DC metadata imported' and the label color will be changed to white.\n"+
" Warning: Existing labels will be lost"
importOptInstText = importOptInst.add('statictext', undefined, body, {multiline:true});
if (Folder.fs == "Windows"){
importOptInstText.minimumSize = [650,200];
importOptInstText.maximumSize = [650,200];
}
else{
importOptInstText.minimumSize = [650,240];
importOptInstText.maximumSize = [650,240];
}
importOptInst.cancelBtn = importOptInst.add('button', undefined, 'Close');
importOptInst.cancelBtn.onClick = function(){
importOptInst.hide();
importOptInst.close();
}
importOptInst.show();
importOptInst.active = true;
}
// Select image files location
imageLocBox = importPanel.add('panel', undefined, "Import to files in selected folder");
imageLocBox.spacing = 2;
imageLocBox.margins = 5;
imageLocBox.alignment = 'left';
// Spacer
spacer3 = imageLocBox.add( 'group' );
spacer3.minimumSize = [10,5]
// folder path of files to be imported to
imageLocGroup = imageLocBox.add('group');
imageLocGroup.orientation = 'row';
imageLocGroup.spacing = 2;
imageLoc = imageLocGroup.add('statictext', undefined, "");
imageLoc.minimumSize = [660,20];
imageLoc.maximumSize = [660,20];
imageLoc.helpTip = imageFolderPathTT;
// subfolders option
imageLocLblGrp = imageLocBox.add('group');
imageLocLblGrp.orientation = 'row';
imageLocLblGrp.alignment = 'left';
imageLocLblGrp.indent = 3;
imageLocSubfoldersCb = imageLocLblGrp.add('checkbox', undefined, "include subfolders");
imageLocSubfoldersCb.alignment = 'left';
imageLocSubfoldersCb.onClick = function toggleImportSub(){
if (imageLocSubfoldersCb.value == true){
dataSourceOptions.enabled = true
IgnoreExtCb.value = false;
IgnoreExtCb.enabled = false;
}
if (imageLocSubfoldersCb.value == false){
dataSourceOptions.enabled = false;
dataSourceOptions.Name.value = true;
dataSourceOptions.Path.value = false;
IgnoreExtCb.value = true;
IgnoreExtCb.enabled = true;
}
}
// Spacer
spacer5 = imageLocBox.add( 'group' );
spacer5.minimumSize = [10,20];
// Select the .txt file to be imported
dataSourceBox = importPanel.add('panel', undefined, "Metadata text file");
dataSourceBox.spacing = 3;
dataSourceBox.margins = 5;
// Spacer
spacer4 = dataSourceBox.add( 'group' );
spacer4.minimumSize = [100,10];
dataSourceGrp = dataSourceBox.add('statictext', undefined, "file location:");
dataSourceGrp.alignment = 'left';
dataSourceGrp.indent = 3;
dataSourceGrp.minimumSize = [160,20];
dataSourceGrp.minimumSize = [160,20];
dataSourceGroup = dataSourceBox.add('group');
dataSourceGroup.orientation = 'row';
dataSourceGroup.spacing = 2;
dataSource = dataSourceGroup.add('edittext', undefined, "");
dataSource.minimumSize = [550,25];
dataSource.maximumSize = [550,25];
dataSource.alignment = 'center';
dataSource.helpTip = textFilePathTT;
dataSourceBrowse = dataSourceGroup.add('button', undefined, "Browse");
dataSourceBrowse.minimumSize = [80,25];
dataSourceBrowse.maximumSize = [80,25];
dataSourceBrowse.helpTip = textFileBrowseTT;
dataSourceFileAlert = dataSourceBox.add('statictext', undefined, "? Enter location of a tab-delimited .txt file");
dataSourceFileAlert.graphics.foregroundColor = dataSourceFileAlert.graphics.newPen (dataSourceFileAlert.graphics.PenType.SOLID_COLOR, [1,0,0], 1);
dataSourceFileAlert.alignment = 'left';
dataSourceFileAlert.justify = 'left';
dataSourceFileAlert.minimumSize = [300,20];
dataSourceFileAlert.maximumSize = [300,20];
dataSourceFileAlert.indent = 20;
dataSourceFileAlert.visible = false;
// opens file browser to pick the location of the metadata text file to be imported to images
dataSourceBrowse.onClick = function(){
var filePath = File.openDialog( 'Select the text file (.txt)', "TXT Files:*.txt" );
if(filePath){
// dataSource.text = filePath.toString().split ("%20").join (" ");
dataSource.text = filePath.fsName.toString().split ("%20").join (" ");// PATH EDIT
testTextFileExists();
dataSource.helpTip = textFilePathTT;
}
}
dataSourceOptions = importPanel.add('panel', undefined, "Match on");
dataSourceOptions.Name = dataSourceOptions.add('radiobutton', undefined, "Filename");
dataSourceOptions.Name.value = true;
dataSourceOptions.Path = dataSourceOptions.add('radiobutton', undefined, "Path and filename");
dataSourceOptions.alignChildren = 'left';
dataSourceOptions.minimumSize = [310, undefined];
dataSourceOptions.spacing = 2;
writeOptions = importPanel.add('panel', undefined, "Existing Data");
writeOptions.minimumSize = [310, undefined];
writeOptions.spacing = 2;
writeOptions.overwriteRb = writeOptions.add('radiobutton', undefined, "Overwrite all fields");
writeOptions.overwriteRb.value = true
writeOptions.appendRb = writeOptions.add('radiobutton', undefined, "Write only to empty fields");
writeOptions.appendRb.value = true;
writeOptions.alignChildren = 'left';
writeOptions.minimumSize = [310, undefined]
// Panel for options
importOptionsGrp = importPanel.add('group', undefined, undefined);
importOptions = importOptionsGrp.add('panel', undefined, "Options");
importOptions.alignChildren = 'left';
importOptions.minimumSize = [275, undefined];
importOptions.spacing = 2;
ignoreExt = importOptions.add('group', undefined, "");
IgnoreExtCb = ignoreExt.add('checkbox', undefined, "Ignore file extensions");
IgnoreExtCb.minimumSize = [200, undefined];
// IgnoreExtCb.helpTip = IgnoreExtCbTT;
addLabel = importOptions.add('group', undefined, "");
addLabelCb = addLabel.add('checkbox', undefined, "Set Thumbnail Label");
addLabelCb.minimumSize = [200, undefined];
// addLabelCb.helpTip = addLabelTT;
// import Options Instructions button
importOptionsButton = importOptionsGrp.add('button', undefined, "?");
importOptionsButton.alignment = 'right';
importOptionsButton.minimumSize = [32,25];
importOptionsButton.maximumSize = [32,25];
importOptionsButton.helpTip = clickInstrucTT;
importOptionsButton.onClick = showImportOptInst
/* no longer needed - folder navigation is done in Bridge UI
// check to see if the folder of images specified exists
function testImportImagesFolder(){
var selectedFolder = Folder(imageLoc.text.split(" ").join("%20"));
if (imageLoc.text && selectedFolder.exists == false){
importImageFolderOK = false;
imageLocAlert.visible = true;
}
else if (imageLoc.text && selectedFolder.exists == true){
importImageFolderOK = true;
imageLocAlert.visible = false;
}
toggleImportBtn();
}
*/
// check to see if the import file is .txt file
function testTextFileExists(){
// get just the directory
var textFile = File(dataSource.text.split(" ").join("%20"));
var fileExtensionIndex = dataSource.text.lastIndexOf(".") // index of last "."
var fileExtension = dataSource.text.slice(fileExtensionIndex+1); // just the file extension based on lastIndexOf period (".")
if (fileExtension != "txt"){ // is it a .txt file?
importTextFileOK = false;
dataSourceFileAlert.text = "Must be a tab-delimined text (.txt) file";
dataSourceFileAlert.visible = true;
}
if (dataSource.text && textFile.exists == false){ // does the file exist?
importTextFileOK = false;
dataSourceFileAlert.text = "File not found. Click 'Browse' to locate file"
dataSourceFileAlert.visible = true;
}
if (fileExtension == "txt" && dataSource.text && textFile.exists == true){ // is it a .xt file and does it exist?
importTextFileOK = true;
dataSourceFileAlert.visible = false;
}
toggleImportBtn();
}
function toggleImportBtn(){
if (importTextFileOK == true ){ // removed importImageFolderOK == true &&
importBtn.enabled = true;
}
else{
importBtn.enabled = false;
}
}
// test to see if the paths entered by user exist
// no longer needed imageLoc.addEventListener('changing',function(){testImportImagesFolder()});
dataSource.addEventListener('changing',function(){testTextFileExists()});
// Import button
importBtn = importPanel.add('button', undefined, "Import");
importBtn.minimumSize = [150,40];
importBtn.maximumSize = [150,40];
importBtn.onClick = importFromFile;
// Create a text file on the desktop with only the headers. This can be used as a template in Excel to create properly formatted text for the import function
function createTemplate(){
var vraTemplate = new File (desktop+""+mdMenu+"_import_default template.txt")
vraTemplate.encoding = "UTF8";
vraTemplate.open ("w", "TEXT", "ttxt");
// Loop through array of headers (properties) and write them to the .txt file
for (var L1 = 0; L1 < fieldsArr.length; L1++) vraTemplate.write (fieldsArr[L1].Label + "\t");
// Close the file ""+mdMenu+"_import_template.txt"
vraTemplate.close();
Window.alert ("A new file named:\n\n"+mdMenu+"_import_default template.txt\n\nhas been created on your desktop", "Success!")
}
// Cancel button
cancelBtn = mainWindow.add('button', undefined, "Cancel");
cancelBtn.minimumSize = [100, 25];
cancelBtn.maximumSize = [100, 25];
cancelBtn.alignment = 'right';
cancelBtn.onClick = function(){
var appDataPlgnSet = new File (appDataFwdSlash + plgnPrefs + plgnOpt + plgnSet);
appDataPlgnSet.encoding = "UTF8";
appDataPlgnSet.open ("w", "TEXT", "ttxt");
appDataPlgnSet.write (exportWhich.folderRb.value + "|");
appDataPlgnSet.write (exportWhich.subfoldersCb.value + "|");
appDataPlgnSet.write (exportWhich.fieldsArrRb.value + "|");
appDataPlgnSet.write (exportOptions.datesCb.value + "|");
appDataPlgnSet.write (dataSource.text + "|");
appDataPlgnSet.write (writeOptions.appendRb.value+ "|");
appDataPlgnSet.write (writeOptions.overwriteRb.value + "|");
appDataPlgnSet.write (IgnoreExtCb.value+ "|");
appDataPlgnSet.write (addLabelCb.value+ "|");
appDataPlgnSet.write (exportOptionsLfCb.value+"|");
appDataPlgnSet.write (exportChoice+"|");
appDataPlgnSet.write (exportWhich.folderEt.text + "|");
appDataPlgnSet.write (imageLoc.text+ "|");
appDataPlgnSet.write (imageLocSubfoldersCb.value+ "|");
appDataPlgnSet.write (dataSourceOptions.Path.value+ "|");
appDataPlgnSet.write (dataSourceOptions.Name.value+ "|");
appDataPlgnSet.write (dataSourceOptions.enabled+ "|");
appDataPlgnSet.write (IgnoreExtCb.enabled+ "|");
appDataPlgnSet.write (mode+ "|");
appDataPlgnSet.write (lastViewedHeadersPanel);
appDataPlgnSet.close();
// close hte main UI window
mainWindow.hide();
mainWindow.close();
}
// if file 'appDataFwdSlash/"+mdMenuLabel+"_Import_Export/Options/settings.txt' exists, read settings and apply to dialog
// ~/AppData/Roaming/"+mdMenuLabel+"_Import_Export/Options/settings.txt
// C:\Users\Computer User\AppData\Roaming\"+mdMenuLabel+"_Import_Export\Options
var appDataPlgnSetBkSlash = File (appDataFwdSlash + plgnPrefs + plgnOpt + plgnSet);
if (appDataPlgnSetBkSlash.exists == true){
appDataPlgnSetBkSlash.open ('r');
var pluginSettingsArray = appDataPlgnSetBkSlash.read().split ('|');
appDataPlgnSetBkSlash.close();
try{
if (pluginSettingsArray[0] == "folder") exportWhich.folderRb.value = true;
if (pluginSettingsArray[1] == "true") exportWhich.subfoldersCb.value = true;
if (pluginSettingsArray[2] == "true") exportWhich.fieldsArrRb.value = true;
if (pluginSettingsArray[3] == "false") exportOptions.datesCb.value = false;
if (pluginSettingsArray[4]) dataSource.text = pluginSettingsArray[4];
if (pluginSettingsArray[5] == "true") writeOptions.appendRb.value = true;
if (pluginSettingsArray[6] == "true") writeOptions.overwriteRb.value = true;
if (pluginSettingsArray[7] == "true") IgnoreExtCb.value = true;
if (pluginSettingsArray[8] == "true") addLabelCb.value = true;
if (pluginSettingsArray[9] == "false") exportOptionsLfCb.value = false;
exportChoice = pluginSettingsArray[10];
if (pluginSettingsArray[11]) exportWhich.folderEt.text = pluginSettingsArray[11];
if (pluginSettingsArray[12]) imageLoc.text = pluginSettingsArray[12];
if (pluginSettingsArray[13] == "true") imageLocSubfoldersCb.value = true;
if (pluginSettingsArray[14] == "true") dataSourceOptions.Path.value = true;
if (pluginSettingsArray[15] == "true") dataSourceOptions.Name.value = true;
if (pluginSettingsArray[16] == "false") dataSourceOptions.enabled = false;
if (pluginSettingsArray[17] == "false") IgnoreExtCb.enabled = false;
if (pluginSettingsArray[18]) mode = pluginSettingsArray[18];
if (pluginSettingsArray[19]) lastViewedHeadersPanel = pluginSettingsArray[19]; fieldsTxt.text = "Current Fields: "+lastViewedHeadersPanel;
}
catch(pluginSettingsError){
if (appDataPlgnSetBkSlash.exists == true) appDataPlgnSetBkSlash.remove();
}
}
// if user prefs file contains lastViewedHeadersPanel, load custom fields
var customFilePath = File (appDataFwdSlash + plgnPrefs + plgnHeaders + "/"+lastViewedHeadersPanel + ".txt");
if (customFilePath.exists == true){ // !!! if "- Select Custom -"
customFilePath.open ('r');
customFileText = customFilePath.read()//.split ('|');
customFilePath.close();
fieldsTxt.text = "Current Fields: "+lastViewedHeadersPanel
// convert that to the fieldsArr TODO: fieldsArr is not accessible when export import functions run so it is being re-created several times later in the code. Is there a better way to do this?
var customFileArr = customFileText.split("\n");
fieldsArr = [];
for (var L1 = 0; L1 < customFileArr.length; L1++){
var obj = new Object();
obj = eval('(' + customFileArr[L1] + ')');
fieldsArr.push(obj)
}
// get unique values of namespace and prefix from objects in array
var found = {};
var out = [];
var count = 0;
for(var i = 0; i < fieldsArr.length; i++) {
var namespaceObject = {}
var item = fieldsArr[i].Namespace;
var pre = fieldsArr[i].XMP_Property;
prefixArr = fieldsArr[i].XMP_Property.split(":")
var pre2 = prefixArr[0];
if(found[item] !== 1) {
found[item] = 1;
namespaceObject.namespace = item;
namespaceObject.prefix = pre2;
if(item.length>0){ // this function returns an empty item at the beginning, so only write to the array if it has data
out[count++] = namespaceObject;
}
}
}
// register namspaces in custom fields list
for (var L2 = 0; L2 < out.length; L2++){
// not "file"
if(out[L2].namespace != "file"){
XMPMeta.registerNamespace(out[L2].namespace, out[L2].prefix);
}
}
}
else{
// TODO load Basic fields if customFilePath.exists == false ?
fieldsTxt.text = "Fields: UNDEFINED"
};
// get current Bridge folder and file paths to automatically fill form. Not sure why, but both of the following methods are needed
if(app.document.visibleThumbnails == true){
/* PATH EDIT
var slicePathIndex = app.document.visibleThumbnails[0].spec.toString().lastIndexOf ("/")
var path = app.document.visibleThumbnails[0].spec.toString().substr(0,slicePathIndex+1).split("%20").join(" ")
*/
// var slicePathIndex = app.document.visibleThumbnails[0].spec.fsName.toString().lastIndexOf ("\\")
var path = app.document.presentationPath.split(slash).join("/")+"/"; // app.document.visibleThumbnails[0].spec.fsName.toString().substr(0,slicePathIndex+1).split("%20").join(" ")
exportWhich.folderEt.text = path
imageLoc.text = path
}
// get current Bridge folder and file paths to automatically fill form