View Full Version : Applescript Error NSReceiveEvaluationScriptError: 4(1)

Jun 28, 2008, 10:01 PM
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.

on clicked theObject
set question to contents of text field "textbox" of window "main"

if question = "" then
display dialog "Sorry, but you did not ask a question. Please try again." buttons {"OK"}
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


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.


Jun 28, 2008, 10:10 PM
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!