Preferences blues

Hi there,
I am trying to save some preference setting contained in 2 text fields in a drawer.
I searched and I found some code that I tried to modify.
I do not understand why I get “.", ".plist” in both fields and when I change the text in the fields and then restart rebuild and go my changes are lost and the “.", ".plist” reappears in both fields.
I could really use a hand here.
Thanks

This is what I tried:

(* ==== Properties ==== *)
--settings
property theExcludedFiles : {}
property theExcludedFolders : {}

to loadPrefs(thesePrefs)
	set loadedPrefs to {}
	repeat with i in thesePrefs
		set iName to i's item 1 as text
		if default entry iName of user defaults exists then
			set end of loadedPrefs to contents of default entry iName of user defaults
		else
			set defaultValue to (i's item 2)
			set end of loadedPrefs to defaultValue
			make new default entry at end of every default entry of user defaults with properties {name:iName, contents:defaultValue}
		end if
	end repeat
	return loadedPrefs
end loadPrefs

to savePrefs(thesePrefs)
	repeat with i in thesePrefs
		set entryName to contents of (i's item 1)
		set entryValue to contents of (i's item 2)
		try
			set contents of default entry entryName of user defaults to entryValue
		on error
			make new default entry at end of every default entry of user defaults with properties {name:entryName, contents:entryValue}
		end try
	end repeat
end savePrefs

on launched theObject
	set {theExcludedFiles, theExcludedFolders} to loadPrefs({{theExcludedFiles, {".*", "*.plist"}}, {theExcludedFolders, {"iPhoto Librar*", "*.framework", "*.ilplib", ".*"}}})
	my setSettingsInUI() -- sets the prefs text fields in drawer
end launched

on will quit theObject
	savePrefs(theExcludedFiles, theExcludedFolders)
end will quit

on setSettingsInUI()
	tell drawer "settings" of window "main"
		set contents of text field "excludedFolders" to theExcludedFolders
		set contents of text field "excludedFiles" to theExcludedFiles
	end tell
end setSettingsInUI

When you rebuild, the preferences won’t be saved unless you quit it within your app itself instead of just pressing rebuild in Xcode. (It’s like force quit then)

Try to use something like this to read & save preferences…

 --these three properties are the values at the very first run, they get changed whenever you run it later..
property NW98firstRun : "YES"
property NW98taxRate : 0
property NW98Logo : "None"

--Make sure you use something like set NW98Logo (or whatever) to contents of text field...

on will finish launching theobject
       tell user defaults
              make new default entry at end of default entries with properties {name:"NW98firstRun", contents:NW98firstRun}
              make new default entry at end of default entries with properties {name:"NW98taxRate", contents:NW98taxRate}
              make new default entry at end of default entries with properties {name:"NW98Logo", contents:NW98Logo}
              set NW98firstRun to contents of default entry "NW98firstRun"
              set NW98taxRate to (contents of default entry "NW98taxRate") as real
              set NW98Logo to contents of default entry "NW98Logo"
       end tell
end will finish launching

on will quit theobject
       tell user defaults
              set contents of default entry "NW98firstRun" to NW98firstRun
              set contents of default entry "NW98taxRate" to NW98taxRate
              set contents of default entry "NW98Logo" to NW98Logo
       end tell
       call method "synchronize" of object user defaults
end will quit

Hi RetroDesign
Thanks for the code.
I will try it soon.
Re: When you rebuild, the preferences won’t be saved unless you quit it within your app itself instead of just pressing rebuild in Xcode. (It’s like force quit then)
I tried running Archive Maker in the example and it seems that rebuild and go keeps the changes in the settings. No need to run the appl.

Hmm I didn’t know that… In my app it doesn’t get remembered somehow ? Anyway, no thanks for the code, I ripped it off somewhere on the forum so it isn’t mine…