Add find panel capabilities to some Cocoa apps

Dec 03, '03 10:28:00AM

Contributed by: mistercow

In many Cocoa applications, the developer has decided to leave out the built in find capabilities of OS X. With applications that handle large amounts of text, this can be extremely inconvenient. Luckily, it is possible, with a little work, to modify many applications to support simple find operations.

Note:
This hint requires that you have Apple's Developer Tools installed. It also requires that you run 10.2 or higher, because 10.1 and below didn't have the "find" feature built in. It is generally good practice to modify a copy of an application, so that if you mess something up, you can get back to a working version. Interface Builder automatically keeps backup files (with a "~" at the end of their names), but it's still a good idea to make a backup copy first.

[robg adds: I have not tested this hint...]

Here is the procedure:

  1. Find the main nib file for the application you are editing. To do this, locate the application in the Finder, control-click its icon and select "Show Package Contents" from the contextual menu (if the the menu doesn't have the "Show Package Contents" option, then the application is most likely Carbon, and this hint won't work). Open the folder called "Contents." And in that folder, open the folder "Resources". Look for a file called "MainMenu.nib." The name may be slightly different, but it will be similar. If the file is not in this folder, open the folder called "English.lproj" or a similar folder with your preferred language. If you still can't find the file, then the app is probably Carbon.

  2. Open the "MainMenu.nib" file with Interface Builder. There should be a little menu icon in the "MainMenu.nib" window. Double click this icon.

  3. Check to see if the Find menu exists. If so, skip to step 5.

  4. Make sure you are showing all palettes (if not, hit command-/) and click the menu icon in the Cocoa palette. You should see a list of menu items in rectangles. Drag the item called "Find >" to the "Edit" menu. (traditionally it should be above "Spelling") Save the nib file.

  5. This is the tricky part. You need to find the text field(s) that you want to be findable. In document-based applications (for example Text Edit), you will need to search through the other nib files in "English.lproj" to find which one has the text field(s) you want to find in. If the application is not document-based, chances are the field is in the "MainMenu.nib". You can just double click the window icons in the nib files; they will look more or less like the interface from the application.

  6. After you find the text field you're looking for, select it. In the "NSTextView Info" palette, choose "Attributes" from the popup menu. There should be a check box that says "Uses Find Panel". Check this box, and save the nib file.
That's it! Now you should be able to use find in the modified application.

One last note:
Some applications won't work with this hint. One example is iChat, which is a shame, because it would benefit from find capabilities. You can usually tell if an application won't work if the text field is an "NSView" or something else other than "NSTextView."

Comments (3)


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