Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.4: An AppleScript to do a 'find by name' search System 10.4
Tiger only hintIf 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!

[robg adds: This hint explains how to modify the default Finder search so that it's always set to do a find by name, though that solution is more complex. And this hint explained that using a double-quote as the first character in the Spotlight search will restrict matches to filename (and properties, as in Word docs and ID3 tags) matches only. I like this AppleScript solution for its ease of implementation. As far as activating it, I put the script into a new Automator action and saved it as a Finder plug-in. Now I can do a find by name via the contextual menu, and it will automatically be set to search the selected folder in the Finder. Nice...

Now please, Apple, given the amount of work we're all putting into getting a simple 'find by name' search done, can we please have it back as a default option in 10.4.x?]
    •    
  • Currently 1.50 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[17,401 views]  

10.4: An AppleScript to do a 'find by name' search | 9 comments | Create New Account
Click here to return to the '10.4: An AppleScript to do a 'find by name' search' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: An AppleScript to do a 'find by name' search
Authored by: wackazong on Nov 15, '05 07:29:19AM

Just asking myself wether I did not understand the problem: You can just do a find by name search by typing something in the search box which you will find in the upper right corner of every Finder window, or can't you? Whats the difference to the "Find" window?



[ Reply to This | # ]
10.4: An AppleScript to do a 'find by name' search
Authored by: dfbills on Nov 15, '05 08:05:12AM

This searches content and filenames. If you have 100's of GBs of data, the search is excruciatingly slow.

---
-d



[ Reply to This | # ]
10.4: An AppleScript to do a 'find by name' search
Authored by: adrianm on Nov 15, '05 09:14:24AM

If you find it "excruciatingly slow" with only hundreds of GB of files, maybe you've got problems with your Mac, or you definition of "excruciatingly slow" is a little sensitive...



[ Reply to This | # ]
10.4: An AppleScript to do a 'find by name' search
Authored by: macgruder on Nov 15, '05 09:42:02AM

That's hardly the point though is it?

Searching for file names rather than file contents should not only be blindingly fast and easy it shouldn't be necessary to sift through hundreds of irrelevant returns. Apple does need to enable us to set a default.

Another alternative is to use Quicksilver.



[ Reply to This | # ]
10.4: An AppleScript to do a 'find by name' search
Authored by: cortig on Nov 15, '05 10:00:23AM

If the System is not used in English, then the script needs to be localized using the proper translations for "File" and Findů".
As fart as shortcuts are concerned, I use Keyboard Maestro to launch the script.


---
Alea jacta Ouest



[ Reply to This | # ]
10.4: An AppleScript to do a 'find by name' search
Authored by: bkuestner on Nov 16, '05 10:32:28AM

I tried to localize for a German setup.

I replaced "File" with "Ablage" and "Find..." with "Find..." (and I also tried "Findů", i. e. replacing three dots with one triple-dot, and then I tried adding a blank space after the triple-dot in case there was an invisible space character in the menu).

But I still get an error message in exactly this line: "NSReceiverEvaluationScriptError: 4"

Any idea what the problem might be?

Thanks.



[ Reply to This | # ]
10.4: An AppleScript to do a 'find by name' search
Authored by: Zo-1 on Nov 16, '05 07:40:11PM

No . . .but you could download Laserlight, a free little app made from the script initially posted here that suggested using the clipboard to enter a word without that damn stuttering that occurs as you try to type the letters of a word but Spotlight's already started searching . . . and bypass the whole question. Hope this helps.



[ Reply to This | # ]
10.4: An AppleScript to do a 'find by name' search
Authored by: IvanX on Nov 17, '05 06:31:43AM
One thing you could also try is to replace the line with "File..." and "Find" with this:
click menu item -2 of menu 3 of menu bar 1
This ought to work as long as "File" (or its localized equivalent) is the third menu from the left and "Find..." is the last item before "Color Label".

[ Reply to This | # ]
10.4: An AppleScript to do a 'find by name' search
Authored by: withdave on Feb 13, '06 11:31:34PM
The 'find by name' script no longer works for me as of 10.4.4. I found that the following very simple script is working perfectly for me and probably has a good chance being compatible with future Finder versions. Note you don't have to type an ending quote after your search string. Enjoy.
tell application "Finder"
    activate
    set windowCount to count of windows
end tell
tell application "System Events"
    tell process "Finder"
        click menu item "Findů" of menu "File" of menu bar 1
        repeat until (count of windows) is not windowCount
        end repeat
        keystroke quote
    end tell
end tell


[ Reply to This | # ]