Using UI scripting to enter text in a file dialog

The trick is figuring out how to address the correct control item in the window. See this hint for an explanation of how to get the needed information: http://hints.macworld.com/article.php?story=20111208191312748

This Applescript code will work on a Finder window named "Titan":

-- text field 1 of group 5 of tool bar 1 of window "Titan" of application process "Finder" of application "System Events"
-- button 1 of text field 1 of group 5 of tool bar 1 of window "Titan" of application process "Finder" of application "System Events"

set windowname to "Titan"
-- set this to name of open Finder window you want to deal with

tell application "Finder"
    activate
end tell

tell application "System Events"
    tell process "Finder"
        set value of text field 1 of group 5 of tool bar 1 of window windowname to "Here is some text"
    end tell
end tell

Anyway, the code'll insert "here is some text" into the Finder window's search box. The first 2 lines are comments showing the pieces of the search box. You can probably click on that button too.