On the forums there is an existing script that may do enough of what you want. See this thread Search OO with Applescript