Hello all. I’ve been visiting MacScripter for a while now, so it’s a pleasure to finally be a part of the community.
I am developing an application that will allow the user to set preferences. I have yet to get to the actual application code, I am just playing with the interface at this point. The preferences are stored in the plist file with no problems. In fact, everything is working great except for one section.
I have boxes in my Preferences window, each with various checkboxes and radio buttons. I am using “will finish launching” to register and read my plist properties and “will quit” to get the state of the buttons and checkboxes in the UI and write their properties to the plist (a la the AS “Archive Maker” example). I am using “launched” to set the UI from the plist.
Here’s where things get weird: I am using the exact same syntax for all radio button matrices, but one matrix just will not set up correctly on launch. In other words, the other buttons and checkboxes respond and set themselves up according to the previously set preferences, but this one particular radio button matrix is not responding when the app loads.
Here is the syntax:
tell matrix "radio_buttons" of box "windowBox" of window "preferences" to set current row to propertyInfo
propertyInfo is string data representing the row selected by the user which has been written to the plist file.
Anybody got an idea what may be going on? Let me know if you need more info…
I tried making it an integer, but that doesn’t change the behavior.
This works for one matrix:
tell matrix "radio_otherButtons" of box "otherBox" of window "preferences" to set current row to otherInfo
This doesn’t work for the other:
tell matrix "radio_buttons" of box "windowBox" of window "preferences" to set current row to propertyInfo
Both otherInfo and propertyInfo are now integers. Same window, same syntax, different result.
Here is all the code:
on will finish launching theObject
tell user defaults
make new default entry at end of default entries with properties {name:"otherInfo", contents:otherInfo}
make new default entry at end of default entries with properties {name:"propertyInfo", contents:propertyInfo}
end tell
tell user defaults
set otherInfo to contents of default entry "otherInfo" as number
set propertyInfo to contents of default entry "propertyInfo" as number
end tell
end will finish launching
on launched theObject
tell matrix "radio_otherButtons" of box "otherBox" of window "preferences" to set current row to otherInfo
tell matrix "radio_buttons" of box "windowBox" of window "preferences" to set current row to propertyInfo
end launched
on will quit theObject
tell matrix "radio_otherButtons" of box "otherBox" of window "preferences"
if current row is equal to 1 then
set otherInfo to 1
end if
if current row is equal to 2 then
set otherInfo to 2
end if
if current row is equal to 3 then
set otherInfo to 3
end if
end tell
tell matrix "radio_buttons" of box "windowBox" of window "preferences"
if current row is equal to 1 then
set propertyInfo to 1
end if
if current row is equal to 2 then
set propertyInfo to 2
end if
if current row is equal to 3 then
set propertyInfo to 3
end if
end tell
tell user defaults
set contents of default entry "otherInfo" to otherInfo
set contents of default entry "propertyInfo" to propertyInfo
end tell
end will quit
I recommend to register the user defaults with certain integer values unless the variables are defined before
Omit the coercion as number
on will finish launching theObject
tell user defaults
make new default entry at end of default entries with properties {name:"otherInfo", contents:1}
make new default entry at end of default entries with properties {name:"propertyInfo", contents:1}
end tell
tell user defaults
set otherInfo to contents of default entry "otherInfo"
set propertyInfo to contents of default entry "propertyInfo"
end tell
end will finish launching
the code to save the user defaults can be simplified a lot,
in both cases you are going to save the value of the current row.
on will quit theObject
set otherInfo to current row of matrix "radio_otherButtons" of box "otherBox" of window "preferences"
set propertyInfo to current row of matrix "radio_buttons" of box "windowBox" of window "preferences"
tell user defaults
set contents of default entry "otherInfo" to otherInfo
set contents of default entry "propertyInfo" to propertyInfo
end tell
call method "synchronize" of object user defaults
end will quit
Thanks again, Stefan, especially for helping me simplify my code.
What’s driving me crazy is that that particular matrix will not respond. The code works for everything else in the UI. The state is written to the plist, and all other buttons return to their previous state. Maybe it’s something in IB…