using NSComboBox

Hi all,
I am a newbie.

I want to do this:
Make an array of names
Make a NSComboBox in Interface Builder

Supply the array to NSComboBox
If a name being entered in the combo box by a user is not present in the array, then it should be added to the array.
Is it possible?

Do I have to refer any document other than NSComboBox for doing this?
(If it is simple, please make a sample example for me. When I am new to something, I prefer to learn through examples rather than documentation)


I worked on something similar but I’m not using an array. I’m writing a list to a text file to save values entered in the combo box and when application launches, read the text file and populate the combo box. I needed several computers to be able to access the text file so I placed the text file on a server.

property pathToDataFile : “Macintosh HD:Users:yourHomeFolderName:Desktop:dataFile.txt”

script ComboBoxAppDelegate
property parent : class “NSObject”
property myComboBox : missing value

on AddNewName_(sender)
	set indexOfCurrentItem to myComboBox's indexOfSelectedItem(sender)
	if indexOfCurrentItem is -1 then --item isn't in list so add it
		set ThisValue to myComboBox's stringValue(sender)
		myComboBox's addItemWithObjectValue_(ThisValue)
		set itemList to myComboBox's objectValues(sender)
		writeToFile_(itemList as list)
	end if
end AddNewName_

on writeToFile_(itemList)
	tell current application
		set dataFile to open for access file pathToDataFile with write permission
		set eof of dataFile to 0
		write itemList to dataFile as list
		close access dataFile
	end tell
end writeToFile_

on readFile_()
	tell current application
		set dataFile to open for access file pathToDataFile
		set itemList to read dataFile as list
		close access dataFile
		return itemList
	end tell
end readFile_

on applicationWillFinishLaunching_(aNotification)
	set itemList to readFile_()
	repeat with aValue in itemList
		myComboBox's addItemWithObjectValue_(aValue as string)
	end repeat
end applicationWillFinishLaunching_

on applicationShouldTerminate_(sender)
	return true
end applicationShouldTerminate_

end script

Oh!! I should have mentioned I was working in a Cocoa project.
I guess what you have done is made an applescript studio application.
Hopefully attaching this script to a cocoa class should work.

I am unable to use this script. I want to know how to use this applescript above. Either in Applescript application or cocoa? Anything will do. Can anyone guide me?
(also, the script does not compile unless i replace
property parent : class “NSObject”
property parent: “NSObject”

This is not a AS Studio Application. It was made and runs in ASOC using Xcode 3.2.1

Thanks again for the reply.
I see, a lot has changed since Leopard. Can you please upload this project so that I can stop groping around in the dark.

By converting it to Cocoa, do you mean Objective-C? Otherwise I’ve wasted my time:

Don’t forget to connect the application’s delegate to this object and a button to controle it. And of course the IBOutlet NSComboBox

Hope it works,