I have a project that I am working on and I’m experiencing some problems with it. I have set up a number of User Defaults and have a routine for copying the value pairs to a variable list. I have another handler that converts it to a string that I am writing to a data file. It works fine for the base settings that I start with, but when I add new settings the coercion to a string is not working. I have tried logging the class but only get scientific notation.
property basePagePresets : {{presetName:"Tabloid", PresetList:{{"PageWidth", 11}, {"PageHeight", 17}, {"FacingPages", 0}}}, {presetName:"Letter", PresetList:{{"PageWidth", 8.5}, {"PageHeight", 11}, {"FacingPages", 0}}}, {presetName:"A4", PresetList:{{"PageWidth", 8.2677}, {"PageHeight", 11.6929}, {"FacingPages", 0}}}, {presetName:"A3", PresetList:{{"PageWidth", 11.6929}, {"PageHeight", 16.5354}, {"FacingPages", 0}}}}
to getUserDefaults(defaultsList) -- in main script
set theDefaults to {}
try
tell user defaults
repeat with aDefault in defaultsList
copy {aDefault, contents of default entry aDefault} to end of theDefaults
end repeat
end tell
end try
return theDefaults
end getUserDefaults
on writePresets(presetFile, ThePreset) --in loaded library of handlers
set ASID to AppleScript's text item delimiters
repeat with p from 1 to count of ThePreset
repeat with q from 1 to count of PresetList of item p of ThePreset
set AppleScript's text item delimiters to "-"
set x to (item 1 of item q of PresetList of item p of ThePreset) as string
log x --the value here logs fine
set x to (item 2 of item q of PresetList of item p of ThePreset) as string
log x --the value here logs fine
set item q of PresetList of item p of ThePreset to (item q of PresetList of item p of ThePreset) as string
log (item q of PresetList of item p of ThePreset) --this coerces to an empty string
end repeat
set AppleScript's text item delimiters to ", "
set PresetList of item p of ThePreset to (PresetList of item p of ThePreset) as string
log PresetList of item p of ThePreset
set item p of ThePreset to (presetName of item p of ThePreset & ":" & PresetList of item p of ThePreset)
end repeat
set AppleScript's text item delimiters to ASCII character 10 --return
set ThePreset to ThePreset as string
set AppleScript's text item delimiters to ASID
set PrefsFile to open for access (presetFile) with write permission
try
set eof of PrefsFile to 0 -- to overwrite what's there, or leave this line out to append the clipboard to whatever is already in it.
write ThePreset to PrefsFile
close access PrefsFile
on error
close access PrefsFile
end try
end writePresets
The resulting file is:
The last entry drops the value pairs after the colon. Any ideas?