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.
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_
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”
with
property parent: “NSObject”
)