Help with CSV for Apple ID verification

almennn's picture

almennn

Joined: Sep 17, 2015
No votes yet

Hi all,

First off, all credit to "itsupport" for creating this script: http://www.enterpriseios.com/forum/topic/Apple_ID_verification_script

I'm trying to incorporate using a CSV for email and password into this script but I can't get the script to loop though all lines in the CSV. It gets stuck on the first line.

CSV file i attached.

Code:

set theFile to (choose file with prompt "Select the CSV file")

-- read the file contents:
set f to read theFile
set AppleScript's text item delimiters to ","
-- break the file into paragraphs (c.f. rows)
repeat with row in (paragraphs of f)
-- parse the row into comma-delimited fields
set fields to parseCSV(row as text)
-- now you have your data:
set email to item 1 of fields
set secretWord to item 2 of fields

set ourDomain to "gmail.com"

tell application "Mail"

set selectionMessage to selection -- just select the first message in the folder
set thisMessage to item 1 of selectionMessage
set theseMessages to (every message in (mailbox of thisMessage)) -- if there are no messages selected, warn the user and then quit

if theseMessages is {} then
display dialog "Please select a message first and then run this script." with icon 1
return
end if

repeat with theMessage in theseMessages

-- My emails were formed as follows: ipad-01@domain.com
-- The following code parses the above into two words:
-- Word 'a' is ipad and word 'b' is 01
-- Also, I had set different passwords for each account with the following format: ipad-secretword-01
-- if you have the same password for all of your accounts, set it as the secretWord
-- at the top of this file and leave the script as it is.

set theContent to source of theMessage
set parsedname to do shell script "echo " & (quoted form of theContent) & " | grep 'Delivered-To:'"
set a to word 3 of parsedname
set b to word 3 of parsedname

set aidEmail to email
--set aidPassword to secretWord
set aidPassword to secretWord

set thelist to {} --this will store the URL's

set startofurl to the offset of "https://id" in theContent
set theContent to rich text startofurl through -1 of theContent
set endofurl to offset of "SE" in theContent

-- the following 3 lines of code just clean up the link as it was getting
-- some funny characters because it was encoded as QUOTED PRINTABLE
set theLink to rich text 1 through (endofurl + 5) of theContent
set theLink to replace_chars(theLink, "=3D", "=") of me
set theLink to replace_chars(theLink, "=
", "") of me

tell application "Safari"
open location theLink

delay 7

do JavaScript "document.forms['command']['appleId'].value = '" & aidEmail & "'" in document 1
do JavaScript "document.forms['command']['accountPassword'].value = '" & aidPassword & "'" in document 1
do JavaScript "document.forms['command'].submit()" in document 1

end tell
end repeat
end tell
end repeat

on parseCSV(theText)
set {od, my text item delimiters} to {my text item delimiters, ","}
set parsedText to text items of theText
set my text item delimiters to od
return parsedText
end parseCSV

on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ","
return this_text
end replace_chars

I suspect something is wrong with the parsing. Can someone please help me understand whats wrong?

Top
almennn's picture

almennn

Joined: Dec 3, 2014

I skipped the email part of

Your rating: None

I skipped the email part of the CSV and now it goes through all the lines. BUT, it goes through all of them twice Smile

Code below, any ideas? Smile

set theFile to (choose file with prompt "Select the CSV file")

-- read the file contents:
set f to read theFile
--set AppleScript's text item delimiters to ","
-- break the file into paragraphs (c.f. rows)
repeat with row in (paragraphs of f)
-- parse the row into comma-delimited fields
set fields to parseCSV(row as text)
-- now you have your data:
set secretWord to item 1 of fields

set ourDomain to "gmail.com"

tell application "Mail"

set selectionMessage to selection -- just select the first message in the folder
set thisMessage to item 1 of selectionMessage
set theseMessages to (every message in (mailbox of thisMessage)) -- if there are no messages selected, warn the user and then quit

if theseMessages is {} then
display dialog "Please select a message first and then run this script." with icon 1
return
end if

repeat with theMessage in theseMessages

-- My emails were formed as follows: ipad-01@domain.com
-- The following code parses the above into two words:
-- Word 'a' is ipad and word 'b' is 01
-- Also, I had set different passwords for each account with the following format: ipad-secretword-01
-- if you have the same password for all of your accounts, set it as the secretWord
-- at the top of this file and leave the script as it is.

set theContent to source of theMessage
set parsedname to do shell script "echo " & (quoted form of theContent) & " | grep 'Delivered-To:'"
set a to word 3 of parsedname
set b to word 3 of parsedname

set aidEmail to secretWord
--set aidEmail to a & "@" ourDomain
--set aidPassword to secretWord
set aidPassword to secretWord

set thelist to {} --this will store the URL's

set startofurl to the offset of "https://id" in theContent
set theContent to rich text startofurl through -1 of theContent
set endofurl to offset of "SE" in theContent

-- the following 3 lines of code just clean up the link as it was getting
-- some funny characters because it was encoded as QUOTED PRINTABLE
set theLink to rich text 1 through (endofurl + 5) of theContent
set theLink to replace_chars(theLink, "=3D", "=") of me
set theLink to replace_chars(theLink, "=
", "") of me

tell application "Safari"
open location theLink

delay 7

do JavaScript "document.forms['command']['appleId'].value = '" & aidEmail & "'" in document 1
do JavaScript "document.forms['command']['accountPassword'].value = '" & aidPassword & "'" in document 1
do JavaScript "document.forms['command'].submit()" in document 1

end tell
end repeat
end tell
end repeat

on parseCSV(theText)
set {od, my text item delimiters} to {my text item delimiters, ","}
set parsedText to text items of theText
set my text item delimiters to od
return parsedText
end parseCSV

on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to " "
return this_text
end replace_chars

Top

Who is online?

There are currently 0 admins, 0 users and 16 guests online. Connected users: .

Recent Activity