Setting default values in a text view on opening a preference panel.

I’m trying to set default values in a text view on opening a preference panel. Here is my code:

on will open theObject
log “preferences awake”
tell user defaults
set defaultTime to contents of default entry “timerDefaultTime”
set alertMessage to contents of default entry “timerAlertMessage”
end tell
log “about to set window defaultTime”
set contents of text field “defaultTime” of window “preferences” to defaultTime
log "about to set window alertMessage: " & alertMessage
set content of text view “alertMessage” of scroll view “alertMessage” of window “preferences” to alertMessage
log “finished setting window defaults”
end will open

When this executes it gets to the point where it tried to set the content of the “alertMessage” view and fails with an NSReceiverEvaluationScriptError: 4(1)

Any thoughts?

Ok, I figured this one out. I didn’t realize that the text view is actually a multi-part entity with both a scroll view (the outer container) and the text view inside it, both of which have to be given separate (not necessarily different) names. FOr those trying to do this, you drag the text view onto your window, select it and then int he applescript tab of the info viewer you set a name, e.g. “scrollView1” (this will name the scroll view), then doubleclick inside the scroll view and this will select the text view, again from the applescript tab of the info viewer give this a name, e.g. “textView1”.

Having done this you can now access this via:

set stringVariableFoo to text of text view “textView1” of scroll view “scrollView1” of window “windowName”

or change it via:

set text of text view “textView1” of scroll view “scrollView1” of window “windowName” to stringVariableBar

Good luck.