macoscocoansmenu

Remove (or customize) 'Search' from help menu


My app has the default 'Help' menu. I have removed the 'Help' entry and added a Support entry that links to a forum on my website.

The help menu nib looks like this:

Menu in nib

But once I have the app up and running a new menu item has been suck in:

Menu with search

How can I make the search go away? (Or even better, how could I make it launch a url with params such as http://mywebsite.com/support?search=XXXXX).


Solution

  • You're looking for NSUserInterfaceItemSearching protocol. Return a single search result item and use it to open your custom URL.

    - (void)searchForItemsWithSearchString:(NSString *)searchString resultLimit:(NSInteger)resultLimit matchedItemHandler:(void (^)(NSArray *items))handleMatchedItems
    {
        handleMatchedItems(@[searchString]);
    }
    
    - (NSArray *)localizedTitlesForItem:(id)item
    {
        return @[[NSString stringWithFormat:@"Search for '%@' on my website", [item description]]];
    }
    
    - (void)performActionForItem:(id)item
    {
        // Open your custom url assuming item is actually searchString
    }