Applescript Error NSReceiveEvaluationScriptError: 4(1)

Discussion in 'Mac Programming' started by toddburch, Jun 28, 2008.

  1. macrumors 6502a

    Joined:
    Dec 4, 2006
    Location:
    Katy, Texas
    #1
    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!
     

    Attached Files:

  2. thread starter macrumors 6502a

    Joined:
    Dec 4, 2006
    Location:
    Katy, Texas
    #2
    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
     

    Attached Files:

Share This Page