10.4: More convenient filename searches

Jul 06, '07 07:30:00AM

Contributed by: noworryz

Leopard will have a better file name search capability, but while we wait, searching for file names with wildcards and boolean AND/ORs can be fairly convenient with this hint. First, some setup. Go to your home folder and choose FIle » New Smart Folder from the menu. Click on the minus signs to remove all the search terms, and then click on the plus sign to add one. Click on Kind and choose "Other...". After a short delay, a list will appear. Scroll down and select Raw Query, then press OK. Now copy and paste the following lines (including the blank lines) into the query text box:

(i==' Scroll forward and replace "xxx" with filename, use "||" for OR,  "&&" for AND, "*" for wildcard, "cwd" for case insensitive/any word ')||((kMDItemDisplayName= '*xxx*'cwd) || (kMDItemDisplayName= '*xxx*'cwd))&&(kMDItemContentType!=com.apple.mail.emlx)&&(kMDItemContentType!=public.vcard)&&(kMDItemContentType!=com.apple.safari.bookmark))

Click the Save button and save the search with the name File Name Search. Select it in your home directory, choose File » Get Info, and change the permissions to "Read only." Then drag the smart folder to the sidebar of a Finder window.

Now when you want to search, click on File Name Search in the sidebar of a Finder window, click the Edit button, and follow the instructions in the text box. The text you want to change is in this section of the code:

((kMDItemDisplayName= '*xxx*'cwd) || (kMDItemDisplayName= '*xxx*'cwd))
Just replace the xxx with the filename(s) you'd like to find. For instance, change the first one to Apple and the second to Finder, and the query as written will find all filenames that contain either Apple or Finder. If you want to do an "AND" search, change the || to &&.

[robg adds: If you use this often, you may find it easier to remove the entire first section, which contains the instructions, since you'll have it memorized anyway. Just make the command start with the ((kMDItemDisplayName... bit.]

Comments (10)


Mac OS X Hints
http://hints.macworld.com/article.php?story=200706301607134