I solved this problem by myself.
property myValue : ""
property myPopUp : missing value
on applicationWillFinishLaunching_(aNotification)
tell standardUserDefaults() of current application's NSUserDefaults
registerDefaults_({myValue:myValue})
set myValue to objectForKey_("myValue") as text
end tell
myPopUp's selectItemAtIndex_(myValue - 1)
end applicationWillFinishLaunching_
on myButtonHandler_(sender)
set myValue to (myPopUp's indexOfSelectedItem()) + 1 --Here is the mistake
end myButtonHandler_
on applicationShouldTerminate_(sender)
tell standardUserDefaults() of current application's NSUserDefaults
setObject_forKey_(myValue, "myValue")
end tell
return current application's NSTerminateNow
end applicationShouldTerminate_
I should have written indexOfSelectedItem() but I wrote indexOfSelectedItem.