Do you see the Google search field in the Safari window? Next to the magnifying glass there is a little arrow, which when clicked shows past searches. How can I do that in my program?
I see in the Search Field Attributes that there is Autosave, Max Recents, and Behavior sections for the search box. I filled them in expecting that would do what I want but it didn’t. If needed I could easily write some code to gather the searches into a list so I can present them, but how do I get that little triangle and present past searches under it?
This isn’t a critical problem but it would add a nice touch to my program… so please help if you can. Thanks!
First, I haven’t had the internet all day today because my connection was out. So I haven’t done much searching for answers. But yesterday I read that document a few times and it wasn’t sinking in. I didn’t understand how I could create a menu item the way that one looked in the document. It never dawned on me that I could create another menu in my main nib file. I just always thought that those menu objects were for adding to the standard menu. Finally it occurred to me that I could put one directly into my nib, and wala!!! Now I have that search field… after linking the search field and the new menu.
But now I have to figure out how to populate the menu and do the applescript linking of the menu items. I gave a quick try right now and got an error… but I’m on my way so I’m sure I’ll eventually figure it out. I tried giving the individual menu items an applescript name and then thought I could issue commands under the “on choose menu item” subroutine… but after a quick try at that it didn’t work.
See, that didn’t take long. I now see I can set the tags like 1001, 1002, etc on the menu items. That enabled them for me. Then I found I can use what I originally came up with…
call method “setRecentSearches:” of (text field “searchField” of box 1 of window 1) with parameter {“ping”, “network”}
and that populates the “Item” menu item. Pretty cool. I have to figure out how to do this easily without me writing glue code to keep the searches and the recent searches menu in sync. I’m not good with that though, but I’ll think more on it.
OK, I got it now. For those that follow me here’s a summary of what needs to be done.
– create the search menu and link it the search field
create a new menu item in your nib file and when you open the new menu 3 items will have been created for you automatically called “Item”, “Clear”, “Empty”… and if not then make them yourself
link your new menu to the search field by control dragging from the search field to the window of the new menu and choose “searchMenuTemplate” from the pop-up
– set the attributes of the search menu’s items
3) select each menu item and in the attributes section of the inspector give them tag numbers, 1001 thru 1003
4) the clear and empty items take care of themselves and you only have to handle the item menu
– in your applescript use the following to populate the search menu and the parameter list that you use will show up under the search menu of the search box
– the parameter list just magically appears in place of the “Item” menu item
5) call method “setRecentSearches:” of (text field “searchField” of box 1 of window 1) with parameter {“ping”, “network”}
– how you handle that list is up to you at this point but every time I did a search I set the beginning of my list to the search term and then used the call method to update the recent searches menu. When my list gets too long I just shorten it.
– if you set the auto save parameters of the search field then your search list will be saved automatically and you can use the user defaults system to read it into your application on every launch
That’s it. I hope that helps someone in the future. It really isn’t complicated so good luck.
Are you saying that when you control-drag from the search field to the menu it doesn’t work? Do you mean you don’t see the “searchMenuTemplate” in the pop-up?
If not then try control-dragging to the title bar of the menu i.e. the very top of the menu and not on the middle of the menu.