Targetting UI command keystroke

I am trying to script what should have been a pretty simple thing to do. Basically I am trying to script adding a commonly used command in FrogBlast so that it will be automated.

tell application "System Events"
	tell application process "Frogblast"
		set value of text area 1 of scroll area 2 of splitter group 1 of splitter group 1 of group 1 of window 1 to "<whatever>"
		keystroke return
	end tell
end tell

Basically that adds the text to the chat input field of the frontmost window. Simple yes. The problem is that the keystroke return command it doesn’t go through. I have tried adding ‘tell application “FrogBlast” to activate’ at the beginning of the script but all it does is give me an error saying that it can’t get the applications event dictionary which isn’t surprising since it doesn’t have one. For some reason when I run the script through the script menu the FrogBlast window is no longer the front most window so it doesn’t recieve the return command. I have tried doing this:

tell application "System Events"
	tell application process "FrogBlast"
		set focused of window 1 to true
	end tell
end tell

But that only returns an NSInternalScriptError. So anyone have any ideas?

Try this:

tell app  "System Events"
     tell process "target app"
          set frontmost to true
          --> ...

Perhaps you can avoid bringing the app to the front. Maybe the chat input field recognizes a return in your string and you can forget the keystroke…

tell application "System Events" 
   tell application process "Frogblast" 
      set value of text area 1 of scroll area 2 of splitter group 1 of splitter group 1 of group 1 of window 1 to "<whatever>" & return
   end tell 
end tell 

Ah there we go. Adding the “set frontmost to true” got the job done.

Thanks.