newbie problems with applescript

Howdy!

I’ve just started doing some applescripting today and I’m finding it a bit strange. I’m trying to build a simple GUI to a perl script that I have.

Right now I have created one window with a text field called searchField, a button which has a binding to the return key and a text area called resultArea which is non editable but has a hidden scroll bar.

I have written code for the button:


on clicked theObject
	tell window of theObject
		try
			set searchWord to contents of text field "searchField" as string
			set output to do shell script "/Users/gary/shell_scripts/idict/search.pl " & searchWord
			set contents of text view "resultArea" to output
		on error
			set contents of text view "resultArea" to "Error, something bad happened there, sorry."
		end try
	end tell
end clicked

Everything works in this code except for displaying code in the resultArea. I usually get a NSReceiverEvaluationScriptError: 4 with this. From googling it seems that this error is gotten from naming variables wrong but I’ve checked my code and there aren’t any errors that I can see.

What’s strange is that when I save in the Interface Builder, this bit gets written into the editor:


on action theObject
	(*Add your script here.*)
end action

This is strange as I only have two handlers set in the Interface Builder. The bit for using the perl script and for exiting the app when the window is closed.

What’s really wierd is that I cannot even run the script, it exits with errors:

2004-07-18 21:06:50.587 iDict[3764] An uncaught exception was raised
2004-07-18 21:06:50.610 iDict[3764] Cannot create BOOL from object <_NSControllerObjectProxy: 0x3369b0> of class _NSControllerObjectProxy
2004-07-18 21:06:50.623 iDict[3764] *** Uncaught exception: Cannot create BOOL from object <_NSControllerObjectProxy: 0x3369b0> of class _NSControllerObjectProxy

iDict has exited due to signal 5 (SIGTRAP).

Sorry about the big post and sorry if I’m not making myself clear but all this applescript stuff is pretty new to me. Any help would be appreciated cheers! :slight_smile:

I think that the first problem you’re having is that you’re telling the window to do the shell script, which it doesn’t understand. Remove the tell statement and just add the window reference to the end of each line as needed. I also bracketed the shell script string, mostly for clarity’s sake…but it can make a difference sometimes.

on clicked theObject
   set theWindow to (window of theObject)
   try
      set searchWord to contents of text field "searchField" of theWindow as string
      set output to do shell script ("/Users/gary/shell_scripts/idict/search.pl " & searchWord)
      set contents of text view "resultArea" of theWindow to output
   on error
      set contents of text view "resultArea" of theWindow to "Error, something bad happened there, sorry."
   end try
end clicked 

The second problem, the reappearance of the ‘on action’ handler, is that one of your objects is likely connected to the on action handler. If a connection exists, xcode will not build the project without at least an empty handler there, so it doesn’t get errors. Either find and disconnect the object connected to the handler, or leave it and it shouldn’t hurt anything. If you’re sure that there is nothing connected to an ‘on action’ handler, the nib may be corrupted, and it may never go away.

FYI, this thread should probably be posted in the Applescript Studio forum.

Good luck…
j

Thanks for the help! :slight_smile:

I’m now getting an error: NSReceiverEvaluationScriptError: 4 (1) when i say that the text area is called text view and this message: NSCannotCreateScriptCommandError (10) when I say that it’s a scroll view. I think the problem here is that I’m calling the text area the wrong thing…

Should the

I’ll post future postings to the Applescript Studio Forum.

Try “text field” instead of “text view”

Ah, turns out it should have been


set contents of text view of scroll view "resultArea" of theWindow to output

Is there a way of making text areas display html or clickable text so that I can click on a word in text view which will start an other event?