I'm not sure why you'd want to do this, but it can be done easily enough.
- If you haven't already done so, you need an object acting as the application's delegate i.e.
Code:
[[NSApplication sharedApplication] setDelegate:self];
- Then you need to implement applicationWillTerminate, and put your code in there.
- You could hard code the path of the preference file by looking in ~/Library/Preferences; but the correct way might be to use NSUserDefaults method removePersistentDomainForName (I haven't tried it, so I'm not sure if that deletes the preference file, but I expect it would).