click on lock to authenticate via Applescript

Hi all,
I have an Application which has a lock icon which is button , clicking on that would pop a dialog box where you have to enter username ans passwd. Just like System Preferences -->Accounts where you have to click on the lock to add new account. So i wanted to know how using Applescript can you unlock by providing the username and passwd credentials?

thanks in advance …


if it’s the standard authentication window, you could use this handler

to authenticate()
	tell application "System Events"
		repeat until (exists window "Authenticate" of process "SecurityAgent")
			delay 0.5
		end repeat
		tell window "Authenticate" of process "SecurityAgent"
			tell group 1
				set value of text field 1 to "myNamer"
				set value of text field 2 to "myPassword"
			end tell
			click button "OK" of group 2
		end tell
	end tell
end authenticate

Thanks a lot for your reply, but i still facing a problem.
The script would pop a authentication dialog box with username alone and doesnot set the password.
>> set value of text field 2 to “mypasswd” seems not working.
need more help.

need more information.

Sorry, no offense, but your question is a bit like “what kind of RAM do I need for my Mac”? :wink:

Without knowing the application it’s rather impossible to help.

PS: the script above is a subroutine to be called by a main script to wait for the authentication window and to insert the proper data with GUI scripting

My apologies for not able to communicate what i wanted appropriately. But i was able to solve the problem. You are right, it impossible for you to help without knowing the application … but i am bounded not tell about the application.
I used the ‘keystroke’ command instead of set and also i used UI which made it a bit simpler to write the script.

thanks for all the replies stefan.