Getting Applescript to Type in Safari

I’m trying to get applescript to type a word in Safari (for example fasts) and press return. This while in a shockwave player program.

It will work in one part of the program (a chat room), but not another. Any suggestions?

tell application “Safari”
activate
end tell
tell application “System Events”
keystroke “f”
keystroke “a”
keystroke “s”
keystroke “t”
keystroke “s”
keystroke return
end tell

Seems to me like th following should solve your problem.

tell application “Safari”
activate
tell application “System Events”
keystroke “f”
keystroke “a”
keystroke “s”
keystroke “t”
keystroke “s”
keystroke return
end tell
end tell

Thanks, but no…it doesnt work like that.

I believe it has something to do with shockwave…maybe it doesn’t take instructions from System Events.

The following worked for me, but was only tested in form fields and the location bar. An important note is that the target text field must be active/focused for this to work… i.e. the cursor must be in the text field to type into as if you were going to start typing there. If you try to send the app some keystrokes without any text field being focused, you’ll just get a bunch of error sounds and no reaction. I don’t have a shockwave page to test on, but I would think it would work similarly. You should be able to get the keystrokes to receive in the shockwave object, because you’re telling the app to simulate the keystroke, not the shockwave itself… which is how the app would handle the event were it an ‘actual’ keystroke.

tell application "Safari"
	activate
end tell

tell application "System Events"
	tell application process "Safari"
		delay 0.1
		keystroke "f"
		keystroke "a"
		keystroke "s"
		keystroke "t"
		keystroke "s"
		keystroke return
	end tell
end tell

Good luck,
j