1

I could be over complicating this but I'm pretty new to Applescript so I wanted to reach out here.

Essentially I'm trying to loop a program login for 10 people. The accounts were handed to me in a list, and I figured the best thing to do was to make it an array. I used this script for the array making:

set stringofitems to "jim
pam
oscar
stanley
michael
dwight
creed
angela
kevin
andy"

set text item delimiters to "
"
set listofitems to text items of stringofitems

repeat with theitem in listofitems

    # stuff to do with each item

end repeat

If I want to display an entry from that new array it works:

Here's my script for the looping of the login process:

tell application "System Events"
    tell process "MyApp"
        set frontmost to true 
        click menu item "Sign In" of menu "Account" of menu bar 1
    end tell
end tell

delay 2

set appName to "jim"
set appPass to "hunter2"

tell application "System Events"
    tell process "MyApp"
        set value of text field 1 of window 1 to appName
        set value of text field 2 of window 1 to appPass
        delay 0.4
        key code 36
    end tell
end tell

That works on its own but the main goal here is to maybe, somehow, combine the two so that I can just run the applescript and it runs through each user of the newly created array "listofitems" from the first part.

As a side note, I need create and use the variables "appName" and "appPass" to bypass the Secure Input automation protection stuff.

If there's a way better way of doing it please let me know.

Thank you!

1
  • set userList to the paragraphs of stringOfItems Commented Apr 9, 2020 at 9:31

1 Answer 1

0

I think I figured it out.

Basically, forget the whole "list to array" code, to make it simpler I didn't include that and just made the array myself.

Here's what I cobbled together to get it working:

tell application "MyApp" to activate
delay 1
tell application "System Events"
    tell process "MyApp"
        set frontmost to true
        click menu item "Sign In…" of menu "Account" of menu bar 1
    end tell
end tell

delay 2

tell application "System Events"
    tell process "MyApp"
        click menu button "Options" of window 1
        keystroke "e"
        key code 36
        keystroke "u"
        key code 36
    end tell
end tell

delay 2

set userList to {"jim", "pam", "oscar", "stanley", "michael", "dwight", "creed", "angela", "kevin", "andy"}
repeat with a from 1 to length of userList
end repeat

set appName to item a of userList
    -- this tells the the script, when appName is called, begin with the first entry and continue to the end ("a" from "1"), instead of calling for "item 1" or "item 4", etc.
set appPass to "hunter2"

tell application "System Events"
    tell process "MyApp"
        set value of text field 1 of window 1 to appName
        set value of text field 2 of window 1 to appPass
        delay 0.4
        key code 36
        wait 4
    end tell
end tell
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.