Okay I would like to retain values across runs so my first thought was to use properties, but this doesn’t seem to be working for me. In a very simple example I have a window “w1”, a text field “tf1”. “w1” is tied to awake on nib, “tf1” tied to on changed
property holder : ""
on changed theObject
set holder to contents of theObject
end changed
on awake from nib theObject
set contents of text field "tf1" of theObject to holder
end awake from nib
Program runs, I enter some text, quit, rerun and nothing… No errors and just a blank field. So thinking maybe on changed wasn’t working I add a button “b1” and tie it to clicked.
on clicked theObject
set holder to contents of text field "tf1" of window "w1"
end clicked
Same thing. The program runs without error, but doesn’t work either.
So I recall seeing an article though by Kevin Bradley about Polishing your apps and using Defaults so I thought I would give that a try. So new studio app and here we go:
¢ Window “w1”
¢ Text Field “tf1”
¢ Button “b1”
¢ File’s Owner “theApp” : Application- should quit, Application-will finish launching
So following Kevin’s example as well as some here I came up with this code
on will finish launching theObject
tell user defaults
make new default entry at end of default entries with properties {name:"testHol", contents:""}
set tempVal to (contents of default entry "testHol" of user defaults)
end tell
set contents of text field "t1" of window "w1" to tempVal
end will finish launching
on should quit theObject
set tempVal to (contents of text field "t1" of window "w1")
tell user defaults
set contents of default entry "testHol" to tempVal
end tell
call method "synchronize" of object user defaults
end should quit
When the spp starts though I instantly get the error Can’t make contents of <> “testHol” of <> of <> into type reference
And then a NSReceiverEvaluationScriptError: 4 (1) when I try to quit
So I’m pretty much at a loss here… Can someone explain how to do this/what I am doing wrong?