Hi! I’m trying to expand my use of ‘user defaults’ and I’m having some problems… I want to register an array that will eventually consist of other arrays. That is… i.e. an array called “People” that will have an element “Person” with properties {Name, Age, Address, etc} resulting in something like {{“Joe”, 25, “Neptune”},{“Jack”,56,“Mars”},{…},etc}. This array will be empty the first time the app is run so I can’t register them all at once… I’ll need to add them according to user needs (even delete them… how can I do that?). I’ve been using these handlers with previous apps but I’m having problems on how to do all this now. I’m absolutely confused!
property TheArray : {"People"}
on will open theObject -- window "Main"
RegisterDefaults(TheArray)
.... -- code
end will open
on RegisterDefaults(AllDefaults)
-- AllDefaults is {}
tell user defaults
repeat with i from 1 to (count of AllDefaults) -- or is it TheArray??
make new default entry at end of default entries with properties {name:(item i of AllDefaults), contents:(item i of AllDefaults)} -- or is it AllDefaults??
end repeat
register
end tell
end RegisterDefaults
on ReadDefaults()
set AllDefaults to {}
tell user defaults
repeat with i from 1 to (count of TheArray) -- or is it AllDefaults??
set end of AllDefaults to contents of default entry (item i of TheArray) -- or is it AllDefaults??
end repeat
end tell
return AllDefaults
end ReadDefaults
on WriteDefaults(AllDefaults)
-- AllDefaults is {}
tell user defaults
repeat with i from 1 to (count of TheArray)
set contents of default entry (item i of AllDefaults) to (item i of TheArray)
end repeat
end tell
end WriteDefaults
Any help will be apreciated! Thanks a lot!
AppleScript: XCode 1.1
Browser: Firefox 1.5.0.2
Operating System: Mac OS X (10.3.9)