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