Need help using applescript for log in (keycode?)

I am very new to applescript.

There is a website that I need to log into everyday for school. Using the automator I made an application that would pull up safari, go to the web site, and watch me enter my username. Then I clicked on the text field for my password and typed it in and clicked the log in button. When I tried to get automator to repeat the actions it watched me do it would not type in my password.

I did some googling and found a way to use applescript to do a “key code” or “keystroke” (I don’t remember which) in order to type in my password, hit the tab key and then hit enter. The application worked, but I have since deleted it. Now I need it again. I have recreated everything except the part which types in my password.

I will be extremely thankful to who ever can help me out. This is what I have so far as far as that code.

tell application “Safari”
tell application “Safari” to activate
key code “45”
end tell

This code doesn’t work, i get the error “Expected end of line, etc. but found identifier.” with the word code highlighted.

Thank you so so much.

Model: Macbook
Browser: Safari 525.27.1
Operating System: Mac OS X (10.5)


try something like the below, noting that you will have to hard code your password (not very secure)

tell application "Safari"
	tell application "Safari" to activate
	delay 3
	tell application "System Events"
		tell process "SystemUIServer"
			keystroke "td48sweep" --hard coded password
		end tell
	end tell
end tell


Thanks for the help. I know that is not very secure, but it did work.

Now the next problem is: on that same log in page before I click the log in button there are two drop down menus that I do not know how to select my choice (the watch me in automator did not work). When I made the application before I used the key code numbers for the tab keys, arrow keys, and enter keys in order to make my selection. How can I make a code for that?

Thanks again for the help.


Here are the key code and keystrokes that you are looking for, youll have to assemble them in your code to do what you require, if you run into trouble
post a link to the page and areas of the drop boxs your trying to access.

key code 123 – left arrow Key

key code 124 – right arrow Key

key code 126 – up arrow Key

key code 125 – down arrow Key

keystroke tab

keystroke return



Thanks Budgie! Using the script you provided I was able to make the the code work. I had left out the " tell application “System Events”
tell process “SystemUIServer”" and thus was unable to use the “key code” lines. Thanks so much again.