forked from jjanover/AppleID
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnterprise iOS Apple ID Creator.applescript
1353 lines (1101 loc) · 60.9 KB
/
Enterprise iOS Apple ID Creator.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
(*
code to find all elements on iTunes page, for use with "verifyPage()"
tell application "System Events"
set elementCount to count of every UI element of UI element 1 of scroll area 3 of window 1 of application process "iTunes"
set everyElement to every UI element of UI element 1 of scroll area 3 of window 1 of application process "iTunes"
set everyProperty to {}
repeat with loopCounter from 1 to (count of items in everyElement)
try
set everyProperty to everyProperty & 1
set item loopCounter of everyProperty to (properties of item loopCounter of everyElement)
end try
end repeat
set everyTitle to {}
repeat with loopCounter from 1 to (count of items in everyProperty)
set everyTitle to everyTitle & ""
try
set item loopCounter of everyTitle to (title of item loopCounter of everyProperty)
end try
end repeat
end tell
*)
--TO DO:
--write itunes running check
--write file output section for account status column
--write check for account status of "completed" or "skipped"
--Global Vars
--start localization
--Set country code to adapt script, code according to http://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
-- Set iTunesCountryCode to your country code and adjust specific parts of code between 'start localization' and 'end localization' to your needs.
property iTunesCountryCode : ""
--property iTunesCountryCode : "FRA"
--property iTunesCountryCode : "POL"
--end localization
--Used for storing a list of encountered errors. Written to by various handlers, read by checkForErrors()
global errorList
set errorList to {}
--Used for controlling the running or abortion of the script. Handler will run as long as scriptAction is "Continue". Can also be set to "Abort" to end script, or "Skip User" to skip an individual user.
global scriptAction
set scriptAction to "Continue"
--Store the current user number (based off line number in CSV file)
global currentUser
set currentUserNumber to 0
--Used for completing every step in the process, except actually creating the Apple ID. Also Pauses the script at various locations so the user can verify everything is working properly.
property dryRun : true
--Used to store the file location of the iBooks "App Page Shortcut". Updated dynamically on run to reference a child folder of the .app bundle (Yes, I know this isn't kosher)
-- AF 2012-05-14 Open location instead of .inetloc
property ibooksLinkLocation : "itms://itunes.apple.com/us/app/ibooks/id364709193?mt=8"
--Master delay timer for slowing the script down at specified sections. Usefull for tweaking the entire script's speed
property masterDelay : 1
--Maximum time (in seconds) the script will wait for a page to load before giving up and throwing an error
property netDelay : 30
--Used at locations in script that will be vulnerable to slow processing. Multiplied by master delay. Tweak for slow machines. May be added to Net Delay.
property processDelay : 1
--How often should the script check that something has loaded/is ready
property checkFrequency : 0.5
--Used to store supported iTunes versions
property supportedItunesVersions : {"11.2.2", "11.3", "11.3.1", "11.4"}
--Used for checking if iTunes is loading a page
property itunesAccessingString : "Accessing iTunes Store…"
(*
Email
Password
Secret Question 1
Secret Answer 1
Secret Question 2
Secret Answer 2
Secret Question 3
Secret Answer 3
Month Of Birth
Day Of Birth
Year Of Birth
First Name
Last Name
Address Street
Address City
Address State
Address Zip
Phone Area Code
Phone Number
Account Status
*)
--Properties for storing possible headers to check the source CSV file for. Source file will be checked for each of the items to locate the correct columns
property emailHeaders : {"Email", "Email Address"}
property passwordHeaders : {"Password", "Pass"}
property secretQuestion1Headers : {"Secret Question 1"}
property secretAnswer1Headers : {"Secret Answer 1"}
property secretQuestion2Headers : {"Secret Question 2"}
property secretAnswer2Headers : {"Secret Answer 2"}
property secretQuestion3Headers : {"Secret Question 3"}
property secretAnswer3Headers : {"Secret Answer 3"}
property monthOfBirthHeaders : {"Month", "Birth Month", "Month of Birth"}
property dayOfBirthHeaders : {"Day", "Birth Day", "Day Of Birth"}
property yearOfBirthHeaders : {"Year", "Birth Year", "Year Of Birth"}
property firstNameHeaders : {"First Name", "First", "fname"}
property lastNameHeaders : {"Last Name", "Last", "lname"}
property addressStreetHeaders : {"Street", "Street Address", "Address Street"}
property addressCityHeaders : {"City", "Address City"}
property addressStateHeaders : {"State", "Address State"}
property addressZipHeaders : {"Zip Code", "Zip", "Address Zip"}
property phoneAreaCodeHeaders : {"Area Code", "Phone Area Code"}
property phoneNumberHeaders : {"Phone Number", "Phone"}
property rescueEmailHeaders : {"Rescue Email (Optional)", "Rescue Email"}
property accountStatusHeaders : {"Account Status"} --Used to keep track of what acounts have been created
property is_interactive : true
(*
code to find all elements on iTunes page, for use with "verifyPage()"
tell application "System Events"
set elementCount to count of every UI element of UI element 1 of scroll area 3 of window 1 of application process "iTunes"
set everyElement to every UI element of UI element 1 of scroll area 3 of window 1 of application process "iTunes"
set everyProperty to {}
repeat with loopCounter from 1 to (count of items in everyElement)
try
set everyProperty to everyProperty & 1
set item loopCounter of everyProperty to (properties of item loopCounter of everyElement)
end try
end repeat
set everyTitle to {}
repeat with loopCounter from 1 to (count of items in everyProperty)
set everyTitle to everyTitle & ""
try
set item loopCounter of everyTitle to (title of item loopCounter of everyProperty)
end try
end repeat
end tell
*)
--TO DO:
--write itunes running check
--write file output section for account status column
--write check for account status of "completed" or "skipped"
--Global Vars
--Used for robotic implementation of the script
--Used for storing a list of encountered errors. Written to by various handlers, read by checkForErrors()
global errorList
set errorList to {}
--Used for controlling the running or abortion of the script. Handler will run as long as scriptAction is "Continue". Can also be set to "Abort" to end script, or "Skip User" to skip an individual user.
global scriptAction
set scriptAction to "Continue"
--Store the current user number (based off line number in CSV file)
global currentUser
set currentUserNumber to 0
--Supported descriptions of iTunes free button
property supportedFreeButtonDescriptions : {"$0.00 Free, iBooks", "0,00 € Free, iBooks"}
set userDroppedFile to false
--Launch the script in interactive mode if no file was dropped (if file was dropped on script, this will never be run, because of the "on open" above)
set droppedFile to ""
if is_interactive then MainMagic(userDroppedFile, droppedFile)
--Check to see if a file was dropped on this script
on open droppedFile
set is_interactive to true
set userDroppedFile to true
MainMagic(userDroppedFile, droppedFile)
end open
on MainMagic(userDroppedFile, droppedFile)
--CHECK ITUNES SUPPORT-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------CHECK ITUNES SUPPORT--
set itunesVersion to version of application "iTunes"
set itunesVersionIsSupported to false
repeat with versionCheckLoopCounter from 1 to (count of items in supportedItunesVersions)
if item versionCheckLoopCounter of supportedItunesVersions is equal to itunesVersion then
set itunesVersionIsSupported to true
exit repeat
end if
end repeat
if itunesVersionIsSupported is false then
if (is_interactive) then
set scriptAction to button returned of (display dialog "iTunes is at version " & itunesVersion & return & return & "It is unknown if this version of iTunes will work with this script." & return & return & "You may abort now, or try running the script anyway." buttons {"Abort", "Continue"} default button "Abort") as text
else
error "iTunes is at version " & itunesVersion & ". It is unknown if this version of iTunes will work with this script."
end if
end if
if scriptAction is "Continue" then
--LOAD USERS FILE-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------LOAD USERS FILE--
set usersFile to loadUsersFile(userDroppedFile, droppedFile) --Load the users file. Returns a list of columns from the source file
if scriptAction is "Continue" then
--Split out header information from each of the columns
set headers to {}
repeat with headerRemoverLoopCounter from 1 to (count of items in usersFile)
set headers to headers & "" --Add an empty item to headers
set item headerRemoverLoopCounter of headers to item 1 of item headerRemoverLoopCounter of usersFile --Save the header from the column
set item headerRemoverLoopCounter of usersFile to (items 2 thru (count of items in item headerRemoverLoopCounter of usersFile) of item headerRemoverLoopCounter of usersFile) --Remove the header from the column
end repeat
set userCount to (count of items in item 1 of usersFile) --Counts the number of users
--seperated column contents (not really necessarry, but it makes everything else a whole lot more readable)
set appleIdEmailColumnContents to item 1 of usersFile
set appleIdPasswordColumnContents to item 2 of usersFile
set appleIdSecretQuestion1ColumnContents to item 3 of usersFile
set appleIdSecretAnswer1ColumnContents to item 4 of usersFile
set appleIdSecretQuestion2ColumnContents to item 5 of usersFile
set appleIdSecretAnswer2ColumnContents to item 6 of usersFile
set appleIdSecretQuestion3ColumnContents to item 7 of usersFile
set appleIdSecretAnswer3ColumnContents to item 8 of usersFile
set monthOfBirthColumnContents to item 9 of usersFile
set dayOfBirthColumnContents to item 10 of usersFile
set yearOfBirthColumnContents to item 11 of usersFile
set userFirstNameColumnContents to item 12 of usersFile
set userLastNameColumnContents to item 13 of usersFile
set addressStreetColumnContents to item 14 of usersFile
set addressCityColumnContents to item 15 of usersFile
set addressStateColumnContents to item 16 of usersFile
set addressZipColumnContents to item 17 of usersFile
set phoneAreaCodeColumnContents to item 18 of usersFile
set phoneNumberColumnContents to item 19 of usersFile
set appleIdRescueColumnContents to item 20 of usersFile
set accountStatusColumnContents to item 21 of usersFile
--PREP-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------PREP--
if is_interactive then
--Ask user if they want to perform a dry run, and give them a chance to cancel
set scriptRunMode to button returned of (display dialog "Would you like to preform a ''dry run'' of the script?" & return & return & "A ''dry run'' will run through every step, EXCEPT actually creating the Apple IDs." buttons {"Actually Create Apple IDs", "Dry Run", "Cancel"}) as text
if scriptRunMode is "Actually Create Apple IDs" then set dryRun to false
if scriptRunMode is "Dry Run" then set dryRun to true
if scriptRunMode is "Cancel" then set scriptAction to "Abort"
else
set dryRun to false
end if
--CREATE IDS-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------CREATE IDS--
if scriptAction is not "Abort" then
set accountStatusSetByCurrentRun to {}
set currentUserNumber to 0
repeat with loopCounter from 1 to userCount
--Increment our current user, just so other handlers can know what user we are on
set currentUserNumber to currentUserNumber + 1
--Get a single user's information from the column contents
set appleIdEmail to item loopCounter of appleIdEmailColumnContents
set appleIdPassword to item loopCounter of appleIdPasswordColumnContents
set appleIdSecretQuestion1 to item loopCounter of appleIdSecretQuestion1ColumnContents
set appleIdSecretAnswer1 to item loopCounter of appleIdSecretAnswer1ColumnContents
set appleIdSecretQuestion2 to item loopCounter of appleIdSecretQuestion2ColumnContents
set appleIdSecretAnswer2 to item loopCounter of appleIdSecretAnswer2ColumnContents
set appleIdSecretQuestion3 to item loopCounter of appleIdSecretQuestion3ColumnContents
set appleIdSecretAnswer3 to item loopCounter of appleIdSecretAnswer3ColumnContents
set rescueEmail to item loopCounter of appleIdRescueColumnContents
set monthOfBirth to item loopCounter of monthOfBirthColumnContents
set dayOfBirth to item loopCounter of dayOfBirthColumnContents
set yearOfBirth to item loopCounter of yearOfBirthColumnContents
set userFirstName to item loopCounter of userFirstNameColumnContents
set userLastName to item loopCounter of userLastNameColumnContents
set addressStreet to item loopCounter of addressStreetColumnContents
set addressCity to item loopCounter of addressCityColumnContents
set addressState to item loopCounter of addressStateColumnContents
set addressZip to item loopCounter of addressZipColumnContents
set phoneAreaCode to item loopCounter of phoneAreaCodeColumnContents
set phoneNumber to item loopCounter of phoneNumberColumnContents
set accountStatus to item loopCounter of accountStatusColumnContents
delay masterDelay
SignOutItunesAccount() ---------------------------------------------------------------------------------------------------------------------------------------------------------Signout Apple ID that is currently signed in (if any)
--delay 10
installIbooks() ---------------------------------------------------------------------------------------------------------------------------------------------------------------------Go to the iBooks App page location to kick off Apple ID creation with no payment information
delay 1 --Fix so iTunes is properly tested for, instead of just manually delaying
repeat
set lcdStatus to GetItunesStatusUntillLcd("Does Not Match", itunesAccessingString, 4, "times. Check for:", 120, "intervals of", 0.25, "seconds") ------------------------Wait for iTunes to open (if closed) and the iBooks page to load
if lcdStatus is "Matched" then exit repeat
delay masterDelay
end repeat
CheckForErrors() ------------------------------------------------------------------------------------------------------------------------------------------------------------------Checks for errors that may have been thrown by previous handler
if scriptAction is "Abort" then exit repeat -----------------------------------------------------------------------------------------------------------------------------------If an error was detected and the user chose to abort, then end the script
ClickCreateAppleIDButton() -----------------------------------------------------------------------------------------------------------------------------------------------------Click "create Apple ID" button on pop-up window
ClickContinueOnPageOne() ------------------------------------------------------------------------------------------------------------------------------------------------------Click "Continue" on the page with the title "Welcome to the iTunes Store"
CheckForErrors() ------------------------------------------------------------------------------------------------------------------------------------------------------------------Checks for errors that may have been thrown by previous handler
if scriptAction is "Abort" then exit repeat -----------------------------------------------------------------------------------------------------------------------------------If an error was detected and the user chose to abort, then end the script
AgreeToTerms() -------------------------------------------------------------------------------------------------------------------------------------------------------------------Check the "I have read and agreed" box and then the "Agree" button
CheckForErrors() ------------------------------------------------------------------------------------------------------------------------------------------------------------------Checks for errors that may have been thrown by previous handler
if scriptAction is "Abort" then exit repeat -----------------------------------------------------------------------------------------------------------------------------------If an error was detected and the user chose to abort, then end the script
log {"Creating ", appleIdEmail}
ProvideAppleIdDetails(appleIdEmail, appleIdPassword, appleIdSecretQuestion1, appleIdSecretAnswer1, appleIdSecretQuestion2, appleIdSecretAnswer2, appleIdSecretQuestion3, appleIdSecretAnswer3, rescueEmail, monthOfBirth, dayOfBirth, yearOfBirth) ----------------Fills the first page of apple ID details. Birth Month is full text, like "January". Birth Day and Birth Year are numeric. Birth Year is 4 digit
CheckForErrors() ------------------------------------------------------------------------------------------------------------------------------------------------------------------Checks for errors that may have been thrown by previous handler
if scriptAction is "Abort" then exit repeat -----------------------------------------------------------------------------------------------------------------------------------If an error was detected and the user chose to abort, then end the script
ProvidePaymentDetails(userFirstName, userLastName, addressStreet, addressCity, addressState, addressZip, phoneAreaCode, phoneNumber) -------------Fill payment details, without credit card info
CheckForErrors() ------------------------------------------------------------------------------------------------------------------------------------------------------------------Checks for errors that may have been thrown by previous handler
if scriptAction is "Abort" then exit repeat -----------------------------------------------------------------------------------------------------------------------------------If an error was detected and the user chose to abort, then end the script
if scriptAction is "Continue" then ----------------------------------------------------------------------------------------------------------------------------------------------If user was successfully created...
set accountStatusSetByCurrentRun to accountStatusSetByCurrentRun & ""
set item loopCounter of accountStatusSetByCurrentRun to "Created" ----------------------------------------------------------------------------------------------Mark user as created
end if
if scriptAction is "Skip User" then ----------------------------------------------------------------------------------------------------------------------------------------------If a user was skipped...
set accountStatusSetByCurrentRun to accountStatusSetByCurrentRun & ""
set item loopCounter of accountStatusSetByCurrentRun to "Skipped" ----------------------------------------------------------------------------------------------Mark user as "Skipped"
set scriptAction to "Continue" ----------------------------------------------------------------------------------------------------------------------------------------------Set the Script back to "Continue" mode
end if
if scriptAction is "Stop" then exit repeat
end repeat
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Display dialog boxes that confirm the exit status of the script
activate
if is_interactive then
if scriptAction is "Abort" then display dialog "Script was aborted" buttons {"OK"}
if scriptAction is "Stop" then display dialog "Dry run completed" buttons {"OK"}
if scriptAction is "Continue" then display dialog "Script Completed Successfully" buttons {"OK"}
end if
--Fix for multiple positive outcomes
if itunesVersionIsSupported is false then --If the script was run against an unsupported version of iTunes...
if scriptAction is "Continue" and is_interactive then --And it wasn't aborted...
if button returned of (display dialog "Would you like to add iTunes Version " & itunesVersion & " to the list of supported iTunes versions?" buttons {"Yes", "No"} default button "No") is "Yes" then --...then ask the user if they want to add the current version of iTunes to the supported versions list
set supportedItunesVersions to supportedItunesVersions & itunesVersion
display dialog "iTunes version " & itunesVersion & " succesfully added to list of supported versions."
end if
end if
end if
end if
end if
end if
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------End main function
end MainMagic
(*_________________________________________________________________________________________________________________________________________*)
--FUNCTIONS-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------FUNCTIONS--
on loadUsersFile(userDroppedFile, chosenFile)
if userDroppedFile is false then set chosenFile to "Choose"
set readFile to ReadCsvFile(chosenFile) --Open the CSV file and read its raw contents
set readFile to ParseCsvFile(readFile) --Parse the values into a list of lists
set listOfColumnsToFind to {"Email", "Password", "Secret Question 1", "Secret Answer 1", "Secret Question 2", "Secret Answer 2", "Secret Question 3", "Secret Answer 3", "Month Of Birth", "Day Of Birth", "Year Of Birth", "First Name", "Last Name", "Address Street", "Address City", "Address State", "Address Zip", "Phone Area Code", "Phone Number", "Rescue Email (Optional)", "Account Status"}
--Locate the columns in the file
set findResults to {}
repeat with columnFindLoopCounter from 1 to (count of items in listOfColumnsToFind)
set findResults to findResults & ""
set item columnFindLoopCounter of findResults to findColumn((item columnFindLoopCounter of listOfColumnsToFind), readFile) --FindColumn Returns a list of two items. The first item is either "Found" or "Not Found". The second item (if the item was "found") will be a numerical reference to the column that was found, based on its position in the source file
end repeat
--Verify that the columns were found, and resolve any missing columns
repeat with columnVerifyLoopCounter from 1 to (count of items in findResults)
if scriptAction is "Continue" then
if item 1 of item columnVerifyLoopCounter of findResults is "Found" then --Check if the current item to be located was found
set item columnVerifyLoopCounter of findResults to item 2 of item columnVerifyLoopCounter of findResults --Remove the verification information and set the item to just the column number
else --If a column is missing
--Ask the user what they would like to do
if not is_interactive then error "The script was unable to locate the " & item columnVerifyLoopCounter of listOfColumnsToFind & " column. The script cannot continue without this information."
set missingColumnResolution to button returned of (display dialog "The script was unable to locate the " & item columnVerifyLoopCounter of listOfColumnsToFind & " column. The script cannot continue without this information." & return & return & "What would you like to do?" buttons {"Abort Script", "Manually Locate Column"}) as text
--If the user chose to abort
if missingColumnResolution is "Abort Script" then set scriptAction to "Abort"
--If the user chose to manually locate the column
if missingColumnResolution is "Manually Locate Column" then
--Create a list of the columns to choose from, complete with a number at the beginning of each item in the list
set columnList to {}
repeat with createColumnListLoopCounter from 1 to (count of items in readFile) --Each loop will create an entry in the list of choices corresponding to the first row of a column in the original source file
set columnList to columnList & ((createColumnListLoopCounter as text) & " " & item 1 of item createColumnListLoopCounter of readFile) --Dynamically add an incremented number and space to the beginning of each item in the list of choices, and then add the contents of the first row of the column chosen for this loop
end repeat
--Present the list of column choices to the user
set listChoice to choose from list columnList with prompt "Which of the items below is an example of ''" & item columnVerifyLoopCounter of listOfColumnsToFind & "''" --Ask user which of the choices matches what we are looking for
if listChoice is false then --If the user clicked cancel in the list selection dialog box
set scriptAction to "Abort"
else
set item columnVerifyLoopCounter of findResults to (the first word of listChoice as number) --Set the currently evaluating entry of findResults to the column NUMBER (determined by getting the first word of list choice, which corresponds to column numbers) the user selected
end if
end if
end if
else --If an abort has been thrown
exit repeat
end if
end repeat
--Retrieve the contents of the found columns
if scriptAction is "Continue" then
set fileContents to {}
repeat with contentRetrievalLoopCounter from 1 to (count of items in findResults)
set fileContents to fileContents & ""
set item contentRetrievalLoopCounter of fileContents to getColumnContents((item contentRetrievalLoopCounter of findResults), readFile)
end repeat
end if
if scriptAction is "Continue" then
return fileContents
end if
end loadUsersFile
on findColumn(columnToFind, fileContents)
--BEGIN FIND EMAIL BEGIN FIND EMAIL
if columnToFind is "Email" then
return findInList(emailHeaders, fileContents)
end if
--BEGIN FIND PASSWORD BEGIN FIND PASSWORD
if columnToFind is "Password" then
return findInList(passwordHeaders, fileContents)
end if
--BEGIN FIND SECRET QUESTION BEGIN FIND SECRET QUESTION
if columnToFind is "Secret Question 1" then
return findInList(secretQuestion1Headers, fileContents)
end if
--BEGIN FIND SECRET ANSWER BEGIN FIND SECRET ANSWER
if columnToFind is "Secret Answer 1" then
return findInList(secretAnswer1Headers, fileContents)
end if
--BEGIN FIND SECRET QUESTION 2 BEGIN FIND SECRET QUESTION 2
if columnToFind is "Secret Question 2" then
return findInList(secretQuestion2Headers, fileContents)
end if
--BEGIN FIND SECRET ANSWER 2 BEGIN FIND SECRET ANSWER 2
if columnToFind is "Secret Answer 2" then
return findInList(secretAnswer2Headers, fileContents)
end if
--BEGIN FIND SECRET QUESTION 3 BEGIN FIND SECRET QUESTION 3
if columnToFind is "Secret Question 3" then
return findInList(secretQuestion3Headers, fileContents)
end if
--BEGIN FIND SECRET ANSWER 3 BEGIN FIND SECRET ANSWER 3
if columnToFind is "Secret Answer 3" then
return findInList(secretAnswer3Headers, fileContents)
end if
--BEGIN FIND BIRTH MONTH BEGIN FIND BIRTH MONTH
if columnToFind is "Month Of Birth" then
return findInList(monthOfBirthHeaders, fileContents)
end if
--BEGIN FIND BIRTH DAY BEGIN FIND BIRTH DAY
if columnToFind is "Day Of Birth" then
return findInList(dayOfBirthHeaders, fileContents)
end if
--BEGIN FIND BIRTH YEAR BEGIN FIND BIRTH YEAR
if columnToFind is "Year Of Birth" then
return findInList(yearOfBirthHeaders, fileContents)
end if
--BEGIN FIND LAST NAME BEGIN FIND LAST NAME
if columnToFind is "First Name" then
return findInList(firstNameHeaders, fileContents)
end if
--BEGIN FIND LAST NAME BEGIN FIND LAST NAME
if columnToFind is "Last Name" then
return findInList(lastNameHeaders, fileContents)
end if
--BEGIN FIND ADDRESS STREET BEGIN FIND ADDRESS STREET
if columnToFind is "Address Street" then
return findInList(addressStreetHeaders, fileContents)
end if
--BEGIN FIND ADDRESS CITY BEGIN FIND ADDRESS CITY
if columnToFind is "Address City" then
return findInList(addressCityHeaders, fileContents)
end if
--BEGIN FIND ADDRESS STATE BEGIN FIND ADDRESS STATE
if columnToFind is "Address State" then
return findInList(addressStateHeaders, fileContents)
end if
--BEGIN FIND ADDRESS ZIP BEGIN FIND ADDRESS ZIP
if columnToFind is "Address Zip" then
return findInList(addressZipHeaders, fileContents)
end if
--BEGIN FIND PHONE AREA CODE BEGIN FIND PHONE AREA CODE
if columnToFind is "Phone Area Code" then
return findInList(phoneAreaCodeHeaders, fileContents)
end if
--BEGIN FIND PHONE NUMBER BEGIN FIND PHONE NUMBER
if columnToFind is "Phone Number" then
return findInList(phoneNumberHeaders, fileContents)
end if
--BEGIN FIND RESCUE EMAIL BEGIN FIND RESCUE EMAIL
if columnToFind is "Rescue Email (Optional)" then
return findInList(rescueEmailHeaders, fileContents)
end if
--BEGIN FIND ACCOUNT STATUS BEGIN FIND ACCOUNT STATUS
if columnToFind is "Account Status" then
return findInList(accountStatusHeaders, fileContents)
end if
end findColumn
-----------------------------------------
on findInList(matchList, listContents)
try
set findState to "Not Found"
set findLocation to 0
repeat with columnItemLoopCounter from 1 to (count of items of (item 1 of listContents))
repeat with testForMatchLoopCounter from 1 to (count of matchList)
if item columnItemLoopCounter of (item 1 of listContents) is item testForMatchLoopCounter of matchList then
set findState to "Found"
set findLocation to columnItemLoopCounter
exit repeat
end if
end repeat
if findState is "Found" then exit repeat
end repeat
return {findState, findLocation} as list
on error
display dialog "Hmm Well, I was looking for something in the file, and something went wrong." buttons "Bummer"
return 0
end try
end findInList
-----------------------------------------
--BEGIN GET COLUMN CONTENTS BEGIN GET COLUMN CONTENTS
on getColumnContents(columnToGet, fileContents)
set columnContents to {}
repeat with loopCounter from 1 to (count of items of fileContents)
set columnContents to columnContents & 1
set item loopCounter of columnContents to item columnToGet of item loopCounter of fileContents
end repeat
return columnContents
end getColumnContents
-----------------------------------------
on ReadCsvFile(chosenFile)
--Check to see if we are being passed a method instead of a file to open
set method to ""
try
if chosenFile is "Choose" then
set method to "Choose"
end if
end try
try
if method is "Choose" then
set chosenFile to choose file
end if
set fileOpened to (characters 1 thru -((count every item of (name extension of (info for chosenFile))) + 2) of (name of (info for chosenFile))) as string
set testResult to TestCsvFile(chosenFile)
if testResult is yes then
set openFile to open for access chosenFile
set fileContents to read chosenFile
close access openFile
return fileContents
end if
on error
close access openFile
display dialog "Something bjorked when oppening the file!" buttons "Well bummer"
return {}
end try
end ReadCsvFile
-----------------------------------------
on TestCsvFile(chosenFile)
set chosenFileKind to type identifier of (info for chosenFile)
if chosenFileKind is "CSV Document" then
return yes
else
if chosenFileKind is "public.comma-separated-values-text" then
return yes
else
if is_interactive then
display dialog "Silly " & (word 1 of the long user name of (system info)) & ", that file is not a .CSV!" buttons "Oops, my bad"
else
error "File provided not a CSV vile."
end if
return no
end if
end if
end TestCsvFile
-----------------------------------------
on ParseCsvFile(fileContents)
try
set parsedFileContents to {} --Instantiate our list to hold parsed file contents
set delimitersOnCall to AppleScript's text item delimiters --Copy the delimiters that are in place when this handler was called
set AppleScript's text item delimiters to "," --Set delimiter to commas
--Parse each line (paragraph) from the unparsed file contents
set lineCount to (count of paragraphs in fileContents)
repeat with loopCounter from 1 to lineCount --Loop through each line in the file, one at a time
set parsedFileContents to parsedFileContents & 1 --Add a new item to store the parsed paragraph
set item loopCounter of parsedFileContents to (every text item of paragraph loopCounter of fileContents) --Parse a line from the file into individual items and store them in the item created above
end repeat
set AppleScript's text item delimiters to delimitersOnCall --Set Applescript's delimiters back to whatever they were when this handler was called
return parsedFileContents --Return our fancy parsed contents
on error
if is_interactive then
display dialog "Woah! Um, that's not supposed to happen." & return & return & "Something goofed up bad when I tried to read the file!" buttons "Ok, I'll take a look at the file"
else
error "Something goofed up bad when I tried to read the file!"
end if
return fileContents
end try
end ParseCsvFile
-----------------------------------------
on verifyPage(expectedElementString, expectedElementLocation, expectedElementCount, verificationTimeout, requiresGroup)
tell application "System Events"
--
repeat until description of scroll area 1 of window 1 of application process "iTunes" is "Apple logo"
delay (masterDelay * processDelay)
end repeat
my GetItunesStatusUntillLcd("Does Not Match", itunesAccessingString, 4, "times. Check for:", (verificationTimeout * (1 / checkFrequency)), "intervals of", checkFrequency, "seconds")
(*repeat
set lcdStatus to my GetItunesStatusUntillLcd("Does Not Match", itunesAccessingString, 4, "times. Check for:", (verificationTimeout * (1 / checkFrequency)), "intervals of", checkFrequency, "seconds")
if lcdStatus is "Matched" then exit repeat
delay masterDelay
end repeat*)
set elementCount to count every UI element of UI element 1 of scroll area 1 of splitter group 1 of splitter group 1 of window 1 of application process "iTunes"
repeat with timeoutLoopCounter from 1 to verificationTimeout --Loop will be ended before reaching verificationTimeout if the expectedElementString is successfully located
if timeoutLoopCounter is equal to verificationTimeout then return "unverified"
if expectedElementCount is 0 then set expectedElementCount to elementCount --Use 0 to disable element count verification
if expectedElementCount is not elementCount then set expectedElementCount to elementCount --Check all countable elements
if elementCount is equal to expectedElementCount then
set everyTitle to {}
try
if requiresGroup then
set elementToTest to UI element expectedElementLocation of group 1 of UI element 1 of scroll area 1 of splitter group 1 of splitter group 1 of window 1 of application process "iTunes"
else
set elementToTest to UI element expectedElementLocation of UI element 1 of scroll area 1 of splitter group 1 of splitter group 1 of window 1 of application process "iTunes"
end if
set elementProperties to properties of elementToTest
set elementString to title of elementProperties
--set elementString to (text items 1 through (count of text items in expectedElementString) of elementString) as string
if elementString is equal to expectedElementString then
return "verified"
end if
on error
return "unverified"
end try
if elementString is equal to expectedElementString then
return "verified"
end if
end if
delay 1
end repeat
end tell
end verifyPage
-----------------------------------------
on CheckForErrors()
if scriptAction is "Continue" then --This is to make sure a previous abort hasn't already been thrown.
if errorList is not {} then --If there are errors in the list
if not is_interactive then
set errorMessage to "Errors were detected. "
repeat with loopCounter from 1 to (count of items in errorList)
set errorMessage to errorMessage & item loopCounter of errorList & " "
end repeat
error errorMessage
end if
set errorAction to button returned of (display dialog "Errors were detected. What would you like to do?" buttons {"Abort", "Skip User", "Review"} default button "Review") as string
if errorAction is "Abort" then
set scriptAction to "Abort" --This sets the global abort action
return "Abort" --This breaks out of the remainder of the error checker
end if
if errorAction is "Review" then
repeat with loopCounter from 1 to (count of items in errorList) --Cycle through all the errors in the list
if errorAction is "Abort" then
set scriptAction to "Abort" --This sets the global abort action
return "Abort" --This breaks out of the remainder of the error checker
else
set errorAction to button returned of (display dialog "Showing error " & loopCounter & " of " & (count of items in errorList) & ":" & return & return & item loopCounter of errorList & return & return & "What would you like to do?" buttons {"Abort", "Manually Correct"} default button "Manually Correct") as string
if errorAction is "Manually Correct" then set errorAction to button returned of (display dialog "Click continue when the error has been corrected." & return & "If you cannot correct the error, then you may skip this user or abort the entire script" buttons {"Abort", "Skip User", "Continue"} default button "Continue") as string
end if
end repeat
set errorList to {} --Clear errors if we've made it all the way through the loops
set scriptAction to errorAction
end if
end if --for error check
end if --for abort check
end CheckForErrors
-----------------------------------------
on SignOutItunesAccount()
if scriptAction is "Continue" then --This is to make sure an abort hasn't been thrown
tell application "System Events"
--Tell iTunes to open iBooks. Still submits information to Apple but moves the script along much faster
tell application "iTunes" to open location ibooksLinkLocation
delay masterDelay
repeat until description of scroll area 1 of window 1 of application process "iTunes" is "Apple logo"
delay (masterDelay * processDelay)
end repeat
set storeMenu to menu "Store" of menu bar item "Store" of menu bar 1 of application process "iTunes"
set storeMenuItems to title of every menu item of storeMenu
end tell
repeat with loopCounter from 1 to (count of items in storeMenuItems)
if item loopCounter of storeMenuItems is "Sign Out" then
tell application "System Events"
click menu item "Sign Out" of storeMenu
end tell
end if
end repeat
end if
end SignOutItunesAccount
-----------------------------------------
on GetItunesStatusUntillLcd(matchType, stringToMatch, matchDuration, "times. Check for:", checkDuration, "intervals of", checkFrequency, "seconds")
set loopCounter to 0
set matchedFor to 0
set itunesLcdText to {}
repeat
set loopCounter to loopCounter + 1
if loopCounter is greater than or equal to (checkDuration * checkFrequency) then
return "Unmatched"
end if
set itunesLcdText to itunesLcdText & ""
tell application "System Events"
try
--set item loopCounter of itunesLcdText to value of static text 1 of scroll area 1 of window 1 of application process "iTunes"
set item loopCounter of itunesLcdText to value of static text 1 of scroll area 1 of window 1 of application process "iTunes"
end try
end tell
if matchType is "Matches" then
if item loopCounter of itunesLcdText is stringToMatch then
set matchedFor to matchedFor + 1
else
set matchedFor to 0
end if
end if
if matchType is "Does Not Match" then
if item loopCounter of itunesLcdText is not stringToMatch then
set matchedFor to matchedFor + 1
else
set matchedFor to 0
end if
end if
if matchedFor is greater than or equal to matchDuration then
return "Matched"
end if
delay checkFrequency
end repeat
end GetItunesStatusUntillLcd
-----------------------------------------
on installIbooks()
delay (masterDelay * processDelay)
if scriptAction is "Continue" then --This is to make sure an abort hasn't been thrown
-- AF 2012-05-14 Open location instead of .inetloc
tell application "iTunes" to open location ibooksLinkLocation
delay (masterDelay * processDelay)
set pageVerification to verifyPage("iBooks", "iBooks", 42, netDelay, true) --Looking for "iBooks", in the second element, on a page with a count of 39 elements, with a timeout of 5, and it requires the use of "group 1" for checking
if pageVerification is "verified" then --Actually click the button to obtain iBooks
delay (masterDelay * processDelay)
tell application "System Events"
try
set freeButton to button 1 of group 2 of UI element 1 of scroll area 1 of splitter group 1 of splitter group 1 of window "iTunes" of application process "iTunes"
-- check if free button is supported
set freeButtonDescription to description of freeButton
set freeButtonDescriptionIsSupported to false
repeat with freeButtonCheckLoopCounter from 1 to (count of items in supportedFreeButtonDescriptions)
if item freeButtonCheckLoopCounter of supportedFreeButtonDescriptions is equal to freeButtonDescription then
set freeButtonDescriptionIsSupported to true
exit repeat
end if
end repeat
if freeButtonDescriptionIsSupported is true then
click freeButton
else
set errorList to errorList & "Unable to locate supported free button by its description."
end if
on error
set errorList to errorList & "Unable to locate install app button by its description."
end try
end tell
set pageVerification to ""
else --Throw error if page didn't verify
set errorList to errorList & "Unable to verify that iTunes is open at the iBooks App Store Page."
end if
end if
end installIbooks
-----------------------------------------
on ClickCreateAppleIDButton()
delay (masterDelay * processDelay)
if scriptAction is "Continue" then --This is to make sure an abort hasn't been thrown
--Verification text for window:
--get value of static text 1 of window 1 of application process "iTunes" --should be equal to "Sign In to the iTunes Store"
tell application "System Events"
if value of static text 1 of window 1 of application process "iTunes" is "Sign In to the iTunes Store" then
try
click button "Create Apple ID" of window 1 of application process "iTunes"
on error
set errorList to errorList & "Unable to locate and click button ''Create Apple ID'' on ID sign-in window"
end try
else
set errorList to errorList & "Unable to locate sign-in window and click ''Create Apple ID''"
end if
end tell
end if
end ClickCreateAppleIDButton
-----------------------------------------
on ClickContinueOnPageOne()
delay (masterDelay * processDelay)
--start localization
set curExpectedElementString to "Welcome to the iTunes Store"
set curExpectedElementLocation to "Welcome to the iTunes Store"
if iTunesCountryCode is "POL" then
set curExpectedElementString to "Witamy w sklepie iTunes Store"
set curExpectedElementLocation to "Witamy w sklepie iTunes Store"
end if
--end localization
set pageVerification to verifyPage(curExpectedElementString, curExpectedElementLocation, 12, netDelay, false) ----------Verify we are at page 1 of the Apple ID creation page
if pageVerification is "verified" then
try
tell application "System Events"
set contButton to button "Continue" of UI element 1 of scroll area 1 of splitter group 1 of splitter group 1 of window 1 of application process "iTunes"
if title of contButton is "Continue" then
click contButton
else
set errorList to errorList & "Unable to locate and click the Continue button on page ''Welcome to iTunes Store''."
end if
end tell
on error
set errorList to errorList & "Unable to locate and click the Continue button on page ''Welcome to iTunes Store''."
end try
set pageVerification to ""
else
set errorList to errorList & "Unable to verify that iTunes is open at the first page of the Apple ID creation process."
end if
end ClickContinueOnPageOne
-----------------------------------------
on AgreeToTerms()
delay (masterDelay * processDelay)
--start localization
set curExpectedElementString to "Terms and Conditions and Apple Privacy Policy"
set curExpectedElementLocation to "Terms and Conditions and Apple Privacy Policy"
if iTunesCountryCode is "POL" then
set curExpectedElementString to "Warunki oraz Ochrona prywatności firmy Apple"
set curExpectedElementLocation to "Warunki oraz Ochrona prywatności firmy Apple"
end if
--end localization
set pageVerification to verifyPage(curExpectedElementString, curExpectedElementLocation, 16, netDelay, false) ----------Verify we are at page 1 of the Apple ID creation page
if pageVerification is "verified" then
tell application "System Events"
--Check box
--start localization
set curCheckBox to "I have read and agree to these terms and conditions."
set curCheckBoxNum to 4
if iTunesCountryCode is "POL" then
set curCheckBox to "Aby móc używać tej usługi, zapoznaj się z przedstawionymi warunkami i zasadami oraz wyraź na nie zgodę."
set curCheckBoxNum to 5
end if
if iTunesCountryCode is "FRA" then
set curCheckBox to "I have read and agree to these terms and conditions."
set curCheckBoxNum to 5
end if
--end localization
try