-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddressbook2pine.applescript
executable file
·1751 lines (1581 loc) · 74.1 KB
/
addressbook2pine.applescript
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
-- addressbook2pine.applescript
-- addressbook2pine
-- Created by patrick collins on 9/12/05.
-- Last updated 10/17/05.
-- Copyright 2005 Colliantor Studios, All rights reserved.
on will finish launching theObject
set visible of window "paypal" to false
set visible of window "preferences" to false
set visible of window "alert" to false
make new default entry at end of default entries of user defaults with properties {name:"distributionlist"}
make new default entry at end of default entries of user defaults with properties {name:"nicknameid"}
make new default entry at end of default entries of user defaults with properties {name:"usecompanyname"}
make new default entry at end of default entries of user defaults with properties {name:"nickuses"}
make new default entry at end of default entries of user defaults with properties {name:"commentuses"}
make new default entry at end of default entries of user defaults with properties {name:"useemailid"}
make new default entry at end of default entries of user defaults with properties {name:"emailidpref"}
make new default entry at end of default entries of user defaults with properties {name:"idabbrev"}
make new default entry at end of default entries of user defaults with properties {name:"fccpathswitch"}
make new default entry at end of default entries of user defaults with properties {name:"fccpath"}
make new default entry at end of default entries of user defaults with properties {name:"fccfolder"}
make new default entry at end of default entries of user defaults with properties {name:"autobackupswitch"}
make new default entry at end of default entries of user defaults with properties {name:"backuplocationtext"}
make new default entry at end of default entries of user defaults with properties {name:"rememberswitch"}
make new default entry at end of default entries of user defaults with properties {name:"pinelocation"}
make new default entry at end of default entries of user defaults with properties {name:"pinemode"}
make new default entry at end of default entries of user defaults with properties {name:"donation"}
set dist to contents of default entry "distributionlist" of user defaults
set nickuses to contents of default entry "nickuses" of user defaults
set usecompanyname to contents of default entry "usecompanyname" of user defaults
set nicknameid to contents of default entry "nicknameid" of user defaults
set commentuses to contents of default entry "commentuses" of user defaults
set useemailid to contents of default entry "useemailid" of user defaults
set emailidpref to contents of default entry "emailidpref" of user defaults
set idabbrev to contents of default entry "idabbrev" of user defaults
set fccpathswitch to contents of default entry "fccpathswitch" of user defaults
set fccpath to contents of default entry "fccpath" of user defaults
set fccfolder to contents of default entry "fccfolder" of user defaults
set autobackupswitch to contents of default entry "autobackupswitch" of user defaults
set backuplocationtext to contents of default entry "backuplocationtext" of user defaults
set rememberswitch to contents of default entry "rememberswitch" of user defaults
set pinelocation to contents of default entry "pinelocation" of user defaults
set pinemode to contents of default entry "pinemode" of user defaults
set donation to contents of default entry "donation" of user defaults
try
dist
nicknameid
usecompanyname
nickuses
commentuses
useemailid
emailidpref
idabbrev
fccpathswitch
fccpath
fccfolder
autobackupswitch
backuplocationtext
rememberswitch
pinelocation
pinemode
donation
on error
my settheuserdefaults()
set contents of default entry "pinelocation" of user defaults to ""
set contents of default entry "backuplocationtext" of user defaults to ""
set contents of default entry "donation" of user defaults to ""
set donation to ""
call method "synchronize" of object user defaults
end try
if donation "true" then
set visible of window "paypal" to true
beep
end if
end will finish launching
on changed
set contents of default entry "fccpath" of user defaults to contents of text field "fccpath" of window "preferences"
end changed
on choose menu item theObject
set checkpopup to name of theObject as string
if checkpopup contains "pinemode" then
set theselection to (title of current menu item of theObject as string)
set contents of default entry "pinemode" of user defaults to theselection
call method "synchronize" of object user defaults
if theselection = "convert os x address book to pine" then
my enablefieldspine()
else if theselection = "convert pine .addressbook to os x" then
my disablefieldspine()
end if
end if
if checkpopup contains "nickuses" then
set theselection to (title of current menu item of theObject as string)
set contents of default entry "nickuses" of user defaults to theselection
call method "synchronize" of object user defaults
end if
if checkpopup contains "commentuses" then
set theselection to (title of current menu item of theObject as string)
set contents of default entry "commentuses" of user defaults to theselection
call method "synchronize" of object user defaults
end if
if checkpopup contains "emailidpref" then
set theselection to (title of current menu item of theObject as string)
set contents of default entry "emailidpref" of user defaults to theselection
call method "synchronize" of object user defaults
end if
if checkpopup contains "fccfolder" then
set theselection to (title of current menu item of theObject as string)
set contents of default entry "fccfolder" of user defaults to theselection
call method "synchronize" of object user defaults
tell window "preferences"
if theselection = "name" then
set the contents of text field "fccfoldertext" to "(full name of contact will be used)"
else if theselection = "group" then
set the contents of text field "fccfoldertext" to "(first group ID of contact will be used)"
else if theselection = "email" then
set the contents of text field "fccfoldertext" to "(first email address of contact will be used)"
else if theselection = "none" then
set the contents of text field "fccfoldertext" to ""
end if
end tell
end if
if name of theObject is "preferences" then
my setdefaults()
set visible of window "preferences" to true
end if
if name of theObject is "donate" then
tell application "System Events" to open location "https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=patrick@collinatorstudios.com&item_name=addressbook2pine&no_shipping=1&no_note=1&tax=0¤cy_code=USD&lc=US&bn=PP%2dDonationsBF&charset=UTF%2d8"
end if
if name of theObject is "visit" then
tell application "System Events" to open location "http://collinatorstudios.com"
end if
end choose menu item
on clicked theObject
global skiplist
global totalskip
global preferencelist
global successlist
global successlistdetail
global successful
global pathinformation
global backupinformation
global autobackuplocation
global fmode
global VersionData
set VersionData to word 2 of paragraph 2 of (do shell script "sw_vers")
if name of theObject is "donate" then
tell application "System Events" to open location "https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=patrick@collinatorstudios.com&item_name=addressbook2pine&no_shipping=1&no_note=1&tax=0¤cy_code=USD&lc=US&bn=PP%2dDonationsBF&charset=UTF%2d8"
end if
if name of theObject is "Done" then
set visible of window "preferences" to false
end if
if name of theObject is "okbutton" then
set visible of window "aboutaddressbook2pine" to false
end if
if name of theObject is "defaults" then
my settheuserdefaults()
my setdefaults()
end if
if name of theObject is "donated" then
if (state of button "donated" of window "paypal" as boolean) then
set contents of default entry "donation" of user defaults to "true"
else
set contents of default entry "donation" of user defaults to ""
end if
call method "synchronize" of object user defaults
end if
if name of theObject is "distributionlist" then
if (state of button "distributionlist" of window "preferences" as boolean) then
set contents of default entry "distributionlist" of user defaults to "on"
else
set contents of default entry "distributionlist" of user defaults to "off"
end if
call method "synchronize" of object user defaults
end if
if name of theObject is "companycards" then
if (state of button "companycards" of window "preferences" as boolean) then
set contents of default entry "usecompanyname" of user defaults to "on"
else
set contents of default entry "usecompanyname" of user defaults to "off"
end if
call method "synchronize" of object user defaults
end if
if name of theObject is "nicknameid" then
if (state of button "nicknameid" of window "preferences" as boolean) then
set contents of default entry "nicknameid" of user defaults to "on"
else
set contents of default entry "nicknameid" of user defaults to "off"
end if
call method "synchronize" of object user defaults
end if
if name of theObject is "useemailid" then
if (state of button "useemailid" of window "preferences" as boolean) then
set contents of default entry "useemailid" of user defaults to "on"
tell window "preferences"
set enabled of popup button "emailidpref" to true
set enabled of matrix "idabbrev" to true
end tell
else
set contents of default entry "useemailid" of user defaults to "off"
tell window "preferences"
set enabled of popup button "emailidpref" to false
set enabled of matrix "idabbrev" to false
end tell
end if
call method "synchronize" of object user defaults
end if
if name of theObject is "usefullid" then
set contents of default entry "idabbrev" of user defaults to "off"
end if
if name of theObject is "useabbrev" then
set contents of default entry "idabbrev" of user defaults to "on"
end if
if name of theObject is "fccpathswitch" then
if (state of button "fccpathswitch" of window "preferences" as boolean) then
set contents of default entry "fccpathswitch" of user defaults to "on"
tell window "preferences"
set enabled of text field "fccpath" to true
set enabled of text field "fccfoldertext" to true
set enabled of popup button "fccfolder" to true
end tell
else
set contents of default entry "fccpathswitch" of user defaults to "off"
tell window "preferences"
set enabled of text field "fccpath" to false
set enabled of text field "fccfoldertext" to false
set enabled of popup button "fccfolder" to false
end tell
end if
call method "synchronize" of object user defaults
end if
if name of theObject is "autobackupswitch" then
if (state of button "autobackupswitch" of window "preferences" as boolean) then
set contents of default entry "autobackupswitch" of user defaults to "on"
tell window "preferences"
set enabled of button "backuplocation" to true
end tell
else
set contents of default entry "autobackupswitch" of user defaults to "off"
tell window "preferences"
set enabled of button "backuplocation" to false
end tell
end if
call method "synchronize" of object user defaults
end if
if name of theObject is "rememberswitch" then
if (state of button "rememberswitch" of window "preferences" as boolean) then
set contents of default entry "rememberswitch" of user defaults to "on"
tell window "preferences"
set enabled of button "pinelocation" to true
end tell
else
set contents of default entry "rememberswitch" of user defaults to "off"
tell window "preferences"
set enabled of button "pinelocation" to false
end tell
end if
call method "synchronize" of object user defaults
end if
if name of theObject is "pinelocation" then
set pinelocation to contents of default entry "pinelocation" of user defaults
if pinelocation = "" then
set browsepath to path to home folder
else
set browsepath to (pinelocation as POSIX file as Unicode text) as alias
end if
try
set pinelocationmac to choose folder default location browsepath with prompt "Select folder where .addressbook file is to be saved" with invisibles
set contents of default entry "pinelocation" of user defaults to POSIX path of pinelocationmac
call method "synchronize" of object user defaults
set contents of text field "pinelocationtext" of window "preferences" to "current location: " & contents of default entry "pinelocation" of user defaults
end try
end if
if name of theObject is "backuplocation" then
try
set autobackuplocation to choose folder default location (path to home folder) with prompt "Select folder for OS X Address Book backups" with invisibles
set contents of default entry "backuplocationtext" of user defaults to the POSIX path of the autobackuplocation
call method "synchronize" of object user defaults
set contents of text field "backuplocationtext" of window "preferences" to "current location: " & contents of default entry "backuplocationtext" of user defaults
end try
end if
if name of theObject is "backuplocation2" then
try
set autobackuplocation to choose folder default location (path to home folder) with prompt "Select folder for OS X Address Book backups" with invisibles
set contents of default entry "backuplocationtext" of user defaults to the POSIX path of the autobackuplocation
call method "synchronize" of object user defaults
set visible of window "alert" to false
call method "performClick:" of (button "startbutton" of window "addressbook2pine")
on error
return
end try
end if
if name of theObject is "details" then
if (state of button "details1" of window "addressbook2pine" as boolean) and (state of theObject as boolean) then
call method "performClick:" of (button "details1" of window "addressbook2pine")
end if
set theFrame to bounds of (window of theObject)
-- call method "setHidden:" of (button "bigdetails" of window "addressbook2pine") with with parameter
set enabled of button "bigdetails" of window "addressbook2pine" to false
set title of button "bigdetails" of window "addressbook2pine" to ""
tell my application "addressbook2pine"
if totalskip = 1 then
set skipmessage to (totalskip & " contact was not converted because it has no email address:" & return & return & skiplist) as string
else
set skipmessage to (totalskip & " contacts were not converted because they have no email address:" & return & return & skiplist) as string
end if
if totalskip = 0 and successful 0 then
set skipmessage to ("No contacts were skipped, all were successfully converted!" & return & return & pathinformation) as string
else if totalskip = 0 and successful = 0 then
set skipmessage to "No contacts found."
end if
if VersionData < "10.5" then
tell text view "terminal" of scroll view "terminal" of window "addressbook2pine"
set text color to {65535, 0, 0}
set contents of text view "terminal" of scroll view "terminal" of window "addressbook2pine" to skipmessage
end tell
else
tell scroll view "terminal" of window "addressbook2pine"
set text color of text view "terminal" to {65535, 0, 0}
set contents of text view "terminal" to skipmessage
end tell
end if
end tell
if (state of theObject as boolean) then
set (item 2 of theFrame) to (item 2 of theFrame) - 250
else
set (item 2 of theFrame) to (item 2 of theFrame) + 250
end if
call method "setFrame:display:animate:" of (window of theObject) with parameters {theFrame, true, true}
end if
if name of theObject is "details1" then
if (state of button "details" of window "addressbook2pine" as boolean) and (state of theObject as boolean) then
call method "performClick:" of (button "details" of window "addressbook2pine")
end if
set theFrame to bounds of (window of theObject)
-- call method "setHidden:" of (button "bigdetails" of window "addressbook2pine") without with parameter
set enabled of button "bigdetails" of window "addressbook2pine" to true
if (state of button "bigdetails" of window "addressbook2pine" as boolean) then
set title of button "bigdetails" of window "addressbook2pine" to "click here for regular import details"
tell my application "addressbook2pine"
if successful = 1 then
set successmessage to (fmode & backupinformation & pathinformation & successful & " contact was successfully converted:" & return & successlistdetail & preferencelist) as string
else
set successmessage to (fmode & backupinformation & pathinformation & successful & " contacts were successfully converted:" & return & successlistdetail & preferencelist) as string
end if
if successful = 0 and totalskip 0 then
set successmessage to "No contacts were successfully converted."
else if successful = 0 and totalskip = 0 then
set successmessage to "No contacts found."
end if
if VersionData < "10.5" then
tell text view "terminal" of scroll view "terminal" of window "addressbook2pine"
set text color to {0, 65535, 0}
set contents of text view "terminal" of scroll view "terminal" of window "addressbook2pine" to successmessage
end tell
else
tell scroll view "terminal" of window "addressbook2pine"
set text color of text view "terminal" to {0, 65535, 0}
set contents of text view "terminal" to successmessage
end tell
end if
end tell
else
set title of button "bigdetails" of window "addressbook2pine" to "click here for more successful import details"
tell my application "addressbook2pine"
if successful = 1 then
set successmessage to (fmode & successful & " contact was successfully converted:" & return & return & successlist) as string
else
set successmessage to (fmode & successful & " contacts were successfully converted:" & return & return & successlist) as string
end if
if successful = 0 and totalskip 0 then
set successmessage to "No contacts were successfully converted."
else if successful = 0 and totalskip = 0 then
set successmessage to "No contacts found."
end if
if VersionData < "10.5" then
tell text view "terminal" of scroll view "terminal" of window "addressbook2pine"
set text color to {0, 65535, 0}
set contents of text view "terminal" of scroll view "terminal" of window "addressbook2pine" to successmessage
end tell
else
tell scroll view "terminal" of window "addressbook2pine"
set text color of text view "terminal" to {0, 65535, 0}
set contents of text view "terminal" to successmessage
end tell
end if
end tell
end if
if (state of theObject as boolean) then
set (item 2 of theFrame) to (item 2 of theFrame) - 250
else
set (item 2 of theFrame) to (item 2 of theFrame) + 250
end if
call method "setFrame:display:animate:" of (window of theObject) with parameters {theFrame, true, true}
end if
if title of theObject is "click here for more successful import details" then
if (state of button "bigdetails" of window "addressbook2pine" as boolean) then
set title of button "bigdetails" of window "addressbook2pine" to "click here for regular import details"
tell my application "addressbook2pine"
if successful = 1 then
set successmessage to (fmode & backupinformation & pathinformation & successful & " contact was successfully converted:" & return & successlistdetail & preferencelist) as string
else
set successmessage to (fmode & backupinformation & pathinformation & successful & " contacts were successfully converted:" & return & successlistdetail & preferencelist) as string
end if
if successful = 0 and totalskip 0 then
set successmessage to "No contacts were successfully converted."
else if successful = 0 and totalskip = 0 then
set successmessage to "No contacts found."
end if
if VersionData < "10.5" then
tell text view "terminal" of scroll view "terminal" of window "addressbook2pine"
set text color to {0, 65535, 0}
set contents of text view "terminal" of scroll view "terminal" of window "addressbook2pine" to successmessage
end tell
else
tell scroll view "terminal" of window "addressbook2pine"
set text color of text view "terminal" to {0, 65535, 0}
set contents of text view "terminal" to successmessage
end tell
end if
end tell
end if
end if
if title of theObject is "click here for regular import details" then
if not (state of theObject as boolean) then
set title of button "bigdetails" of window "addressbook2pine" to "click here for more successful import details"
tell my application "addressbook2pine"
if successful = 1 then
set successmessage to (fmode & successful & " contact was successfully converted:" & return & return & successlist) as string
else
set successmessage to (fmode & successful & " contacts were successfully converted:" & return & return & successlist) as string
end if
if successful = 0 and totalskip 0 then
set successmessage to "No contacts were successfully converted."
else if successful = 0 and totalskip = 0 then
set successmessage to "No contacts found."
end if
if VersionData < "10.5" then
tell text view "terminal" of scroll view "terminal" of window "addressbook2pine"
set text color to {0, 65535, 0}
set contents of text view "terminal" of scroll view "terminal" of window "addressbook2pine" to successmessage
end tell
else
tell scroll view "terminal" of window "addressbook2pine"
set text color of text view "terminal" to {0, 65535, 0}
set contents of text view "terminal" to successmessage
end tell
end if
end tell
end if
end if
if name of theObject is "cancel" then
set visible of window "alert" to false
end if
if title of theObject is "Start" then
my resettext()
set autobackupswitch to contents of default entry "autobackupswitch" of user defaults
set backuplocationtext to contents of default entry "backuplocationtext" of user defaults
if autobackupswitch = "on" then
if backuplocationtext = "" then
set visible of window "alert" to true
beep
return
end if
try
set datestring to current date
set shortdate to short date string of (datestring as date)
set backupnamespace to "Address Book - " & shortdate & ".abbu"
set backupname to my charreplacelist({" ", "/"}, {"\\ ", ":"}, backupnamespace)
set completename to backuplocationtext & backupname
try
do shell script "rm -r " & completename
end try
set shelltalk to "mkdir " & completename & " ; cp ~/Library/Application\\ Support/AddressBook/AddressBook.data " & completename & "/ ; ditto ~/Library/Application\\ Support/AddressBook/Images " & completename & "/Images"
do shell script (shelltalk)
set completemac to completename as POSIX file as Unicode text
set completemac to my charreplace("\\", "", completemac)
set completemac to completemac as alias
my extentionhide(completemac)
on error errorMsg number errorNum
display dialog ("There was an error backing up OS X addressbook.
" & "Error: " & errorNum as string) & " " & errorMsg & "" buttons {"Ok"} default button 1
return
end try
end if
if (state of button "details1" of window "addressbook2pine" as boolean) then
call method "performClick:" of (button "details1" of window "addressbook2pine")
end if
if (state of button "details" of window "addressbook2pine" as boolean) then
call method "performClick:" of (button "details" of window "addressbook2pine")
end if
set enabled of button "startbutton" of window "addressbook2pine" to false
set enabled of button "details" of window "addressbook2pine" to false
set enabled of button "details1" of window "addressbook2pine" to false
call method "setHidden:" of (button "details1" of window "addressbook2pine") without with parameter
tell window "addressbook2pine"
set contents of progress indicator "statusbar" to 0
end tell
set pinemode to contents of default entry "pinemode" of user defaults
set uniqueid to 0
set successful to 0
set totalskip to 0
set compilationList to ""
set skiplist to {}
set successlist to {}
set successlistdetail to {}
if autobackupswitch = "on" and backuplocationtext "" then
set backupinformation to "OS X Address Book file \"" & backupnamespace & "\" saved to: " & backuplocationtext & return & return
else
set backupinformation to ""
end if
if pinemode = "convert os x address book to pine" then
call method "setHidden:" of (button "details" of window "addressbook2pine") without with parameter
set f to false
my scanning(f)
set fmode to ""
set {totalcount, totalemailcountdistoff} to my countemails()
my hideapps()
my convertstart(totalcount, f)
set tid to text item delimiters
set {dist, nickuses, usecompanyname, nicknameid, commentuses, useemailid, emailidpref, idabbrev, fccpathswitch, fccpath, fccfolder, autobackupswitch, backuplocationtext, rememberswitch, pinelocation, pinemode} to my gettheuserdefaults()
set preferencelist to {return & return & "distribution lists: [" & dist & "], use unique nickname id: [" & nicknameid & "], use name field of company cards: [" & usecompanyname & "], nickname field: [" & nickuses & "], comment field uses: [" & commentuses & "], add email id: [" & useemailid & "], email id uses: [" & emailidpref & "], abbreviate email id: [" & idabbrev & "], use fcc: [" & fccpathswitch & "], fcc path: [" & fccpath & "], fcc folder: [" & fccfolder & "]"}
tell application "Address Book" to tell people
repeat with thisPerson in it
tell thisPerson to if (count emails) > 0 then
set {o, p, e, el, g, b, n, f, l, mn, sn, nn, ph, phl} to its {organization, name, email's value, label of email, name of group, birth date, note, first name, last name, middle name, suffix, nickname, value of phone, label of phone}
set VersionData to word 2 of paragraph 2 of (do shell script "sw_vers")
if VersionData > "10.3.9" then
set {u, ul} to its {value of url, label of url}
else
set {u, ul} to {{}, {}}
end if
try
if f = missing value then
end if
on error
set f to missing value
end try
try
set c to its company
on error
set c to false
end try
set eml to e
set ell to el
set gl to g
set uli to ul
set phli to ph
if (item 1 of eml as string) contains "@" and (item 1 of eml as string) contains "." then
set {o, e, el, g, u, ul, b, n, f, l, mn, sn, nn, ph, phl} to my {getFirstname(o), getEmail(e), getEmaillabel(el), getGroup(g), getUrl(u, ul), getUrllabel(ul), getBirthday(b), getNote(n), getFirstname(f), getFirstname(l), getFirstname(mn), getFirstname(sn), getFirstname(nn), getPhone(ph), getPhonelabel(phl)}
set nickfield to {"", "", ""}
if nickuses = "company" then
set gtemp to o
set gtemp to my charremove({",", ":", "@", ";", "[", "]", "(", ")", "<", ">", "\\", "\""}, gtemp)
set gtemp to my charreplace(space, "_", gtemp)
set item 3 of nickfield to gtemp
else if nickuses = "group" then
set gtemp to g
set gtemp to my charremove({",", ":", "@", ";", "[", "]", "(", ")", "<", ">", "\\", "\""}, gtemp)
set gtemp to my charreplace(space, "_", gtemp)
set gtemp to my charreplace(",", "/", gtemp)
set item 3 of nickfield to (gtemp as string)
else if nickuses = "birthday" then
set item 3 of nickfield to b
else if nickuses = "first name" then
set gtemp to f
set gtemp to my charremove({",", ":", "@", ";", "[", "]", "(", ")", "<", ">", "\\", "\""}, gtemp)
set gtemp to my charreplace(space, "_", gtemp)
set item 3 of nickfield to gtemp
else if nickuses = "last name" then
set gtemp to l
set gtemp to my charremove({",", ":", "@", ";", "[", "]", "(", ")", "<", ">", "\\", "\""}, gtemp)
set gtemp to my charreplace(space, "_", gtemp)
set item 3 of nickfield to gtemp
else if nickuses = "first+last" then
set gtemp to f & " " & l
set gtemp to my charremove({",", ":", "@", ";", "[", "]", "(", ")", "<", ">", "\\", "\""}, gtemp)
set gtemp to my charreplace(space, "_", gtemp)
set item 3 of nickfield to gtemp
else if nickuses = "nickname" then
set gtemp to nn
set gtemp to my charremove({",", ":", "@", ";", "[", "]", "(", ")", "<", ">", "\\", "\""}, gtemp)
set gtemp to my charreplace(space, "_", gtemp)
set item 3 of nickfield to gtemp
else if nickuses = "phone" then
set gtemp to ph
set gtemp to my charremove({":", "@", ";", "[", "]", "(", ")", "<", ">", "\\", "\""}, gtemp)
set gtemp to my charreplace(space, "-", gtemp)
set gtemp to my charreplace(",", "/", gtemp)
set item 3 of nickfield to (phtemp as string)
else if nickuses = "none" then
set item 3 of nickfield to ""
end if
set e to my charremove({" "}, e)
set emailfield to e
set namefield to p
set headings to {"Company: ", "Groups: ", "Birthday: ", "URL: ", "Phone: ", "Notes: "}
if (count gl) < 2 then
set item 2 of headings to "Group: "
end if
set n2 to my charreplace("\"", "'", n)
set notescount to count n2 as string
set notechar to 1
if notescount > 1 then
try
repeat until character notechar of n2 space
if notechar > notescount then exit repeat
set notechar to notechar + 1
end repeat
set n2 to characters notechar through -1 of n2 as string
on error
set n2 to ""
end try
end if
if commentuses = "company" and o "" then
set commentfield to my commentc(headings, o)
else if commentuses = "group" and g "" then
set commentfield to my commentg(headings, gl)
else if commentuses = "birthday" and b "" then
set commentfield to my commentb(headings, b)
else if commentuses = "url" and u "" then
set commentfield to my commentu(headings, u, ul)
else if commentuses = "phone" and phli {} then
set commentfield to my commentp(headings, phl, phli)
else if commentuses = "notes" and n2 "" then
set commentfield to my commentn(headings, n2)
else if commentuses = "all" then
set commentfieldlist to {}
if o "" then
set end of commentfieldlist to my commentc(headings, o)
end if
if g "" then
set end of commentfieldlist to my commentg(headings, gl)
end if
if b "" then
set end of commentfieldlist to my commentb(headings, b)
end if
if u "" then
set end of commentfieldlist to my commentu(headings, u, ul)
end if
if phli {} then
set end of commentfieldlist to my commentp(headings, phl, phli)
end if
if n "" then
set end of commentfieldlist to my commentn(headings, n2)
end if
if (count commentfieldlist) > 0 then
set commentfield to my (listToText from commentfieldlist between ", ")
else
set commentfield to ""
end if
else
set commentfield to ""
end if
set fccfolderstring to ""
if fccpathswitch = "on" then
if fccfolder = "name" then
set fccfolderstring to p
set fccfolderstring to my charreplace(" ", "-", fccfolderstring)
else if fccfolder = "group" then
try
set fccfolderstring to item 1 of gl
set fccfolderstring to my charreplace(" ", "-", fccfolderstring)
on error
set fccfolderstring to "unknown-group"
end try
else if fccfolder = "email" then
try
set fccfolderstring to item 1 of eml
set fccfolderstring to my charreplace(" ", "-", fccfolderstring)
on error
set fccfolderstring to "unknown-group"
end try
end if
set fccfield to fccpath & fccfolderstring
else
set fccfield to ""
end if
if usecompanyname = "on" and f & mn & l & sn as string "" then
set namefield to {}
set namefieldtemp to {f, mn, l, sn}
repeat with i from 1 to 4
if (count item i of namefieldtemp) > 0 then set end of namefield to item i of namefieldtemp
end repeat
set namefield to my (listToText from namefield between space)
else if usecompanyname = "off" and c = true and o "" then
set namefield to o
end if
set namefieldbackup to namefield
set commentfieldbackup to commentfield
set elc to 0
set currentemailcount to (count items of eml)
if dist = "off" and currentemailcount > 1 then
repeat with emc in items of eml
set elc to elc + 1
set uniqueid to uniqueid + 1
set uniqueidpad to my uniqueidpad(uniqueid, totalemailcountdistoff)
set emailfield to emc as string
if nicknameid = "on" then
set item 1 of nickfield to uniqueidpad
end if
if useemailid = "on" then
if emailidpref = "nickname" then
if idabbrev = "on" then
set item 2 of nickfield to (character 1 of item elc of ell)
else
set item 2 of nickfield to item elc of ell
end if
else if emailidpref = "name" then
if idabbrev = "on" then
set namefield to namefieldbackup & " (" & (character 1 of item elc of ell) & ")"
else
set namefield to namefieldbackup & " (" & item elc of ell & ")"
end if
else if emailidpref = "comment" then
if idabbrev = "on" then
set commentfield to "Email id: [" & (character 1 of item elc of ell) & "]"
if commentfieldbackup "" then set commentfield to commentfield & ", " & commentfieldbackup
else
set commentfield to "Email id: [" & item elc of ell & "], " & commentfieldbackup
if commentfieldbackup "" then set commentfield to commentfield & ", " & commentfieldbackup
end if
end if
end if
set nickbackup to nickfield
set nickfield to my listremover(nickfield)
if (nickfield as string) "" then
tell nickfield to my (listToText from nickfield between "_")
end if
set nickfield to nickfield as string
set pineline to {nickfield, namefield, emailfield, fccfield, commentfield}
tell pineline to my (listToText from pineline between tab)
set compilationList to compilationList & pineline & "
"
set nickfield to nickbackup
end repeat
else
set uniqueid to uniqueid + 1
set uniqueidpad to my uniqueidpad(uniqueid, totalcount)
if nicknameid = "on" then
set item 1 of nickfield to uniqueidpad
end if
if useemailid = "on" then
if emailidpref = "nickname" then
if idabbrev = "on" then
set item 2 of nickfield to (character 1 of item 1 of ell)
else
set item 2 of nickfield to item 1 of ell
end if
else if emailidpref = "name" then
if idabbrev = "on" then
set namefield to namefieldbackup & " (" & (character 1 of item 1 of ell) & ")"
else
set namefield to namefieldbackup & " (" & item 1 of ell & ")"
end if
else if emailidpref = "comment" then
if idabbrev = "on" then
set commentfield to "Email id: [" & (character 1 of item 1 of ell) & "]"
if commentfieldbackup "" then set commentfield to commentfield & ", " & commentfieldbackup
else
set commentfield to "Email id: [" & item 1 of ell & "]"
if commentfieldbackup "" then set commentfield to commentfield & ", " & commentfieldbackup
end if
end if
end if
set nickbackup to nickfield
set nickfield to my listremover(nickfield)
if (nickfield as string) "" then
tell nickfield to my (listToText from nickfield between "_")
end if
set nickfield to nickfield as string
set pineline to {nickfield, namefield, emailfield, fccfield, commentfield}
tell pineline to my (listToText from pineline between tab)
set compilationList to compilationList & pineline & "
"
set nickfield to nickbackup
end if
set AppleScript's text item delimiters to ","
set eml2 to eml as string
set url2 to u as string
if dist = "off" and currentemailcount > 1 then
set uniqueidfinal to uniqueid - currentemailcount + 1 & "-" & uniqueid
else
set uniqueidfinal to uniqueid
end if
set successvars to {eml2, o, ph, g, fccfield, b, url2, n}
set successheadings to {"Email: [", "Company: [", "Phone: [", "Group: [", "Fcc: [", "Birthday: [", "Url: [", "Notes: ["}
set successfield to {}
set AppleScript's text item delimiters to ""
repeat with i from 1 to 8
if (count item i of successvars) > 0 then set end of successfield to item i of successheadings & item i of successvars & "]"
end repeat
set beginning of successfield to "Id: [" & uniqueidfinal & "]"
set AppleScript's text item delimiters to ", "
set successfield to successfield as string
set AppleScript's text item delimiters to ""
set successful to successful + 1
set the end of successlistdetail to namefield & ": " & successfield as string
set the end of successlist to namefield
my progress()
my textfieldupdate(p, successful, totalskip, totalcount, VersionData)
else
set totalskip to totalskip + 1
set the end of skiplist to p
my progress()
my textfieldupdate(p, successful, totalskip, totalcount, VersionData)
end if
else
set totalskip to totalskip + 1
set p to its {name}
set the end of skiplist to p
my progress()
my textfieldupdate(p, successful, totalskip, totalcount, VersionData)
end if
end repeat
end tell
set enabled of button "startbutton" of window "addressbook2pine" to true
tell window "addressbook2pine"
set contents of text field "statustextfield" to "Conversion Complete!"
set enabled of button "details" to true
set enabled of button "details1" to true
set the contents of text field "textblock" to "click arrows below for details"
set {successlist, successlistdetail} to my setsuccess(successlist, successlistdetail, "shortoutput.txt", "detailout.txt")
set AppleScript's text item delimiters to ASCII character 10
set skiplist to skiplist's text items as string
set AppleScript's text item delimiters to ""
set skiplist to my sort_list(skiplist, "skipoutput.txt")
set skiplist to my addreturn(skiplist)
if successful 0 then
set folderchoice to my browserfun()
try
set addressbookname to ".addressbook"
set folderchoicepreserve to folderchoice
set posixfolderchoice to the POSIX path of the folderchoicepreserve
set pathinformation to "pine addressbook file saved to: " & posixfolderchoice & addressbookname & return & return
set folderchoice to (folderchoice & addressbookname) as string
set docName to folderchoice as list
set docPointer to (open for access docName with write permission)
set eof of docPointer to 0
write compilationList to docPointer as Çclass utf8È
close access docPointer
on error number -128
tell progress indicator "statusbar" to increment by -(totalcount)
set pathinformation to "*** pine addressbook file not saved ***" & return & return
end try
end if
end tell
else if pinemode = "convert pine .addressbook to os x" then
call method "setHidden:" of (button "details" of window "addressbook2pine") with with parameter
set f to true
set fmode to "*** pine2addressbook mode ***" & (ASCII character 10) & (ASCII character 10)
set addressbook2pinegroup to false
set pinebooklocationfile to choose file with prompt "Choose pine .addressbook file" default location (path to home folder) with invisibles
set pathinformation to "pine addressbook file converted to OS X Address Book from: " & POSIX path of pinebooklocationfile & return & return
tell application "Address Book"
set thegroups to name of groups
repeat with currentgroup in thegroups
if currentgroup as Unicode text = "addressbook2pine" then
set addressbook2pinegroup to true
exit repeat
end if
end repeat
if not addressbook2pinegroup then
make new group at end with properties {name:"addressbook2pine"}
end if
end tell
my startpine("Opening Pine's .addressbook...")
set pinebooklocationfile to pinebooklocationfile as string
my hideapps()
set thefile to pinebooklocationfile
set fileid to open for access file thefile
my startpine("Reading Pine's .addressbook...")
set contentlist to read fileid
close access fileid
set contentlist to contentlist as Unicode text
set contentlist to my (switchText of contentlist from (ASCII character 10) & (ASCII character 32) & ":" & (ASCII character (32)) to "")
set contentlist to my (switchText of contentlist from (ASCII character 10) & (ASCII character 32) to "")
set thelist to paragraphs of contentlist
set thelist2 to {}
my scanning(f)
repeat with z from 1 to (count thelist)
if (count (item z of thelist)) as integer > 0 and (character 1 of item z of thelist) as string = tab then
set item z of thelist to "" & tab & characters 2 through -1 of item z of thelist
end if
end repeat
my startpine("Sorting Contacts...")
repeat with z from 1 to (count thelist)
set AppleScript's text item delimiters to ASCII character 9
if (count item z of thelist) > 1 and item z of thelist does not contain "#DELETED" then
set the end of thelist2 to text items of item z of thelist
end if
end repeat
set AppleScript's text item delimiters to ""
set totalcount to count thelist2
my startpine("Processing Contacts...")
repeat with z from 1 to totalcount
if item 1 of item z of thelist2 contains "_" then
set item 1 of item z of thelist2 to my charreplace("_", space, item 1 of item z of thelist2)
end if
if (count item z of thelist2) < 5 then
repeat until (count item z of thelist2) = 5
set the end of item z of thelist2 to ""
end repeat
end if
end repeat
set y to 0
set x to 0
my convertstart(totalcount, f)
tell application "Address Book"
repeat with x from 1 to totalcount
set thefullnamebackup to item 2 of item x of thelist2