If you're like me, you love Spotlight, but can't imagine what Apple was thinking when they chose to provide Kind and Last Opened as unchangeable default criteria in every new Finder search window. Most of the time, I want to search by file name only, or I get many more hits than I need.
The following AppleScript opens a new Find window and changes the search criteria to Name, and then puts the cursor in the name field. To set it up, launch the AppleScript Utility in /Applications/Applescript, and check both 'Enable GUI Scripting' and 'Show Script Menu in menu bar.' You can set 'Show Library Scripts' to your preference.
Then paste the AppleScript code below into Script Editor, and save it as a new compiled script called "Find By Name." If you want all users on the system to be able to use the script, put it into into /Library/Scripts. If you want it to be available to your user only, put it in the Scripts folder (which you may need to create) in the Library Folder of your home folder. Then, whenever you want to Find By Name, just choose the script from the Script Menu, which is among the icons on the right side of your menu bar.
If you find that the script is choosing Name correctly, but isn't putting the cursor in the name field, try uncommenting the delay 1 line by removing the leading --, and save the script again.
tell application "Finder" to activate
tell application "System Events"
tell process "Finder"
click menu item "Find…" of menu "File" of menu bar 1
tell window 1's splitter group 1's group 1's group 2's group 1
click pop up button 2 of group (count groups)
keystroke ("n" & return)
-- delay 1
try
set value of ((attribute "AXFocused" of text field 1) ¬
of group (count groups)) to 1
end try
end tell
end tell
end tell
If anyone has any suggestions as to the best way to trigger this script with a keyboard shortcut, please post them!
Mac OS X Hints
http://hints.macworld.com/article.php?story=20051111034108434