More about focusing a text field

Hi. I searched here on the focusing of the text fields but none of it seems to help me in this situation. Maybe there is something else that needs to happen before I try the focusing of the text field.

Anyway, I have a script I wrote in plain applescript that I’m trying to turn into an AS Studio project. It works well and pretty much as planned. However, I can’t seem to get the focusing thing working. The interface is pretty simple with 23 text fields to fill in and two buttons - one to start the actions needed and the other to quit. I have it set up so that tabbing from a text field will tab down the first column and then from the bottom of the first to the top of the second. A few of the text fields have default values in them so I don’t necessarily have to fill in every text field and some don’t need to be filled out at all. So, if I use the default values and then have the app do it’s thing, the focus remains where the last text field was edited. I’m trying to reset the focus through a handler I called “textCleaner”. Here’s that bit of code.

on textCleaner(w)
	tell w
		set contents of text field "jobNumber" to "S"
		set contents of text field "description" to ""
		set contents of text field "itemNumber" to ""
		set contents of text field "fSlitW" to "0"
		set contents of text field "fCenter" to "0"
		set contents of text field "sCenter" to "0"
		set contents of text field "rptLength" to "0"
		set contents of text field "maxDecoW" to "0"
		set contents of text field "maxDecoL" to "0"
		set contents of text field "diameter" to "0"
		set contents of text field "c1" to "Cyan (H)"
		set contents of text field "c2" to "Magenta (H)"
		set contents of text field "c3" to "Yellow (H)"
		set contents of text field "c4" to "Black (H)"
		set contents of text field "c5" to ""
		set contents of text field "c6" to ""
		set contents of text field "c7" to ""
		set contents of text field "c8" to ""
		set contents of text field "c9" to ""
		set contents of text field "c10" to ""
		
		set first responder to text field "jobNumber"
	end tell
end textCleaner

The bulk of the script works with Illustrator CS. Ill CS is the front application when my app finishes. The window for my app stays open until I quit it. I don’t know if this has anything to do with the focusing problem or not. All the text fields are reset as I need, so I’m thinking this is not so, but . . . ?

Thank you.

PreTech

P.S. I forgot to mention that w in the code above is set to the window of theObject (theObject being one of the buttons).

Ok, I have determined (by making a small test app) that the problem seems to be with having one of the buttons set with the Return key Equivalent. Why that is is the question.

PreTech

Here’s the code for the test app. This is essentially the same basic setup as in my actual app. Maybe this problem has something to do with where the code is activated.

on clicked theObject
	if name of theObject is "go" then
		set win to window of theObject
		set t1 to contents of text field "t1" of win
		set t2 to contents of text field "t2" of win
		set t3 to contents of text field "t3" of win
		set t4 to contents of text field "t4" of win
		my doSomething(t1, t2, t3, t4)
		my textCleaner(win)
	else
		quit
	end if
end clicked

on textCleaner(w)
	tell w
		set contents of text field "t1" to ""
		set contents of text field "t2" to "7"
		set contents of text field "t3" to "Oh boy."
		set contents of text field "t4" to ""
		
		set first responder to text field "t1"
		set first responder to text field "t1"
	end tell
end textCleaner

on doSomething(t1, t2, t3, t4)
	tell application "Illustrator CS"
		activate
		make new document
		set t to current document
		tell t
			make new text frame with properties {position:{30, 500}, contents:t1 & " " & t2 & " " & t3 & return & t4}
		end tell
	end tell
end doSomething

Thanks.

PreTech

I have tried your script and haven’t found any error/malfunction. I fill in text fields “tf 1” - “tf4”, klick button “go” - it creates the Illustrator document and returns the first responder to “tf1”. The only thing that might be missing is to return your application back to front? (an ‘activate’ comand after ‘my textCleaner(win)’ would do it).

D.

Dominik,

Did you try to set the key equivalent of one of the buttons to return? That seems to be when the problem occurs. The last text field selected remains the focus in this situation.

Thanks for looking into this.

PreTech

Model: dual 1.8 G5
AppleScript: 2.1 (80)
Browser: Safari 412.5
Operating System: Mac OS X (10.4)