In AppleScript when entering password, is a click required I'm writing an AppleScript to toggle on/off a VPN connection for a computer.
I have things more or less working, however, I have to click on the password prompt dialog in order for the script to enter my password.
Here is the code block to put the password in, I added the reopen and activate commands because I thought they would bring the window to focus.
-- Enter the password now!
tell application &quot;System Events&quot;
    tell process &quot;SecurityAgent&quot;
        reopen
        activate
        set value of text field 2 of window 1 to myPass
        click button 2 of window 1
    end tell
end tell

Is there something simple I'm missing?

UPDATE
Ok Update - Actually it looks like it IS entering the password but its after maybe a 6 second delay or something like that.  I'm no sure if that changes the question
Try adding this to your code:

set first responder to text field 2 of window 1


This should bring focus to the text field.

For reference, see this post on MacScripter