Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

toddburch

macrumors 6502a
Original poster
Dec 4, 2006
748
0
Katy, Texas
I'm working through an example (my 2nd one...) in a book and I keep getting an error when I click the button that is associated with this code block below. The line in red causes the error NSReceiveEvaluationScriptError: 4(1). I've typed it out just like in the book.

I'm using Applescript Studio to create the app.

In Interface Builder, or otherwise, how to I determine where the name "textbox" or "main" get associated with the NSTextField or NSWindow? I expected to see them under the Inspector "Attributes" view, but I didn't see them under any of the Inspector views.

Code:
on clicked theObject
	[color=red]set question to contents of text field "textbox" of window "main"[/color]
	
	if question = "" then
		display dialog "Sorry, but you did not ask a question.  Please try again." buttons {"OK"}
		return
	end if
	
	set randomNo to random number from 1 to 3
	
	if randomNo = 1 then
		set answer to "Yes"
	end if
	
	if randomNo = 2 then
		set answer to "No"
	end if
	
	if randomNo = 3 then
		set answer to "Maybe"
	end if
	
	beep
	
	display dialog "question: " & question & "Answer: " & answer buttons {"OK"}
	
end clicked

I googled the error and found several hits, but most pointed to poorly behaving applescripts that others had downloaded, and I'm pretty sure I don't have any of them.

I also use the Xcode debugger, thinking that it might show the button or text field attributes, but I didn't see them there either.

Thanks!
 

Attachments

  • Fortune Teller001.png
    Fortune Teller001.png
    86.8 KB · Views: 82
Nevermind, I figured it out. A shortcoming in the book.

In the Inspector, under the Applescript view, there is a "name" field. I entered the names from the example into this field for both the Window and the Text Field, and that fixed the problem!

Todd
 

Attachments

  • Interface Builder001.png
    Interface Builder001.png
    24 KB · Views: 72
  • Interface Builder002.png
    Interface Builder002.png
    28.6 KB · Views: 70
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.