I’ve gone over so many examples that look exactly like my code here I simply can’t figure out what I’m doing wrong.
I have a single window with one button and one NSTextView. The button is called “test”, the textview is called “view” and the window is called “main” in interface builder. I connected the button to the only script which is this:
on clicked theObject
if the name of theObject is "test" then
log "test button pressed."
set the contents of text view "view" of scroll view "view" of window "main" to "Check it out!"
log "set view code executed"
end if
end clicked
I get no errors when the program builds and no errors when I hit the “test” button … although nothing happens at all when I hit the button other than it flashing.
Checking the run tab for my log statements, I see both of them in there for every click
So what gives? I have a blind eye to the problem … help!
on clicked theObject
if the name of theObject is "test" then
log "test button pressed."
set the contents of text view "view" of scroll view "view" of window "main" to "Check it out!"
log "set view code executed"
end if
end clicked
Did you have any luck with this as I am having the exact same problem.
Also, is there an Apple doco detailing how to reference the various Cocoa GUI components from AppleScript within AppleScript Studio?
If you haven’t named both the text view and the scroll view (in IB, click once on the item to set the name of the scroll view via the AppleScript pane on the info palette, then double-click on the item to set the name of the text view), you can still reference the text view by its index:
set the contents of text view 1 of scroll view "view" of window "main" to "Check it out!"
I just post to help me learn, not to answer sorry :-).
So why you doesn’t get the window of the button directely and ask directely to the window the named component? Like (I don’t adapt the code to your case in order to not add many errors):
on clicked theObject
log "clicked:" & name of theObject
if name of theObject is "OK" then
tell window of theObject
try
set myVar to contents of text field "textFieldName" as text
on error error_message number error_number
set this_error to "Error: " & error_number & ". " & error_message & return
display dialog "error in on clicked button OK: " & this_error
end try
end tell
doStuff()
close panel (window of theObject)
else
log "not handle clicked for " & name of theObject
end if
end clicked