2D Arrays and Repeats

Hello, I’m trying to repeat several arrays at once. Although my original script is lengthy, I’m gong to sum up my dilemma in a simple script:


set webaddress1 to "login1.com"
set webaddress2 to "login2.com"
set webaddress3 to "login3.com"
set webaddress4 to "login4.com"
set theWebaddressList to [webaddress1, webaddress2, webaddress3, webaddress4]

set email1 to "email1@login1.com"
set email2 to "email2@login2.com"
set email3 to "email3@login3.com"
set email4 to "email4@login4.com"
set theEmailList to [email1, email2, email3, email4]

set password1 to "pass1"
set password2 to "pass2"
set password3 to "pass3"
set password4 to "pass4"
set thePasswordList to [password1, password2, password3, password4]

set myLoginArray to [theWebaddressList, theEmailList, thePasswordList]

tell application "Google Chrome"
tell window 1
tell tab 1
open location webaddress1
execute javascript "document.getElementById('inputEmailHandle').value='" & email1 & "'"
execute javascript "document.getElementById('inputPassword').value='" & password1 & "'"
execute javascript "document.forms['login'].submit()"
end tell
end tell
end tell

How can i repeat through the array so that the variables come out simultaneously?

For example: this repeat loop will not work:


repeat with x in theWebaddressList
repeat with y in theEmailList
repeat with z in thePasswordList
tell application "Google Chrome"
tell window 1
tell tab 1
open location theWebaddressList
execute javascript "document.getElementById('inputEmailHandle').value='" & theEmailList & "'"
execute javascript "document.getElementById('inputPassword').value='" & thePasswordList & "'"
execute javascript "document.forms['login'].submit()"
end tell
end tell
end tell
end repeat
end repeat
end repeat

So, how can I use a 2D array to my advantage here? Or is there any other way to configure this? I’d like to go through the script using {webaddress1 with email1 and password1}, and continue with {webaddress2, email2, password2}, etc…

If I understand well the problem, you may try this code.


set webaddress1 to "login1.com"
set webaddress2 to "login2.com"
set webaddress3 to "login3.com"
set webaddress4 to "login4.com"
set theWebaddressList to {webaddress1, webaddress2, webaddress3, webaddress4}

set email1 to "email1@login1.com"
set email2 to "email2@login2.com"
set email3 to "email3@login3.com"
set email4 to "email4@login4.com"
set theEmailList to {email1, email2, email3, email4}

set password1 to "pass1"
set password2 to "pass2"
set password3 to "pass3"
set password4 to "pass4"
set thePasswordList to {password1, password2, password3, password4}

set myLoginArray to {theWebaddressList, theEmailList, thePasswordList}

# Here is a loop used to check that everything works well
repeat with i from 1 to count item 1 of myLoginArray
	log "theLogin : " & (item i of item 1 of myLoginArray)
	log "theEmail : " & (item i of item 2 of myLoginArray)
	log "thePassword : " & (item i of item 3 of myLoginArray)
end repeat

# Here is the true code
tell application "Google Chrome"
	tell window 1
		tell tab 1
			repeat with i from 1 to count item 1 of myLoginArray
				open location (item i of item 1 of mylogginArray)
				execute javascript "document.getElementById('inputEmailHandle').value='" & (item i of item 2 of myLoginArray) & "'"
				execute javascript "document.getElementById('inputPassword').value='" & (item i of item 3 of myLoginArray) & "'"
				execute javascript "document.forms{'login'}.submit()"
			end repeat
		end tell
	end tell
end tell

Yvan KOENIG running El Capitan 10.11.4 in French (VALLAURIS, France) jeudi 7 avril 2016 18:48:36

Works great. Thank you :smiley:

Thanks for the feedback.
You may remove the instructions which I used for tests.

# Here is a loop used to check that everything works well
repeat with i from 1 to count item 1 of myLoginArray
   log "theLogin : " & (item i of item 1 of myLoginArray)
   log "theEmail : " & (item i of item 2 of myLoginArray)
   log "thePassword : " & (item i of item 3 of myLoginArray)
end repeat

I kept the list of lists named myLoginArray but in the posted code it’s not really useful.
Maybe you need to have it in other parts of the complete script.

Yvan KOENIG running El Capitan 10.11.4 in French (VALLAURIS, France) jeudi 7 avril 2016 20:52:43