How can I place cursor at end of text in field, please?

G’day scripters.

Probably a basic question, but I can’t find the answer anywhere.

In a text file that I want the user to enter email addresses in, I can’t work out how to place a return in the text whenever and wherever a user hits ‘return’.

I’m using this to add a return at the end of the text, but then the field selects ALL the text, and does not place the cursor at the end.


on setMailList2:sender
	 	if (last paragraph of my mailAddressesSecondaryError) is not in {"", return} then set my mailAddressesSecondaryError to my mailAddressesSecondaryError & return as text
		my saveTheGeneralData()
	end setMailList2:
	

How can I place the cursor at the end, or insert a ‘return’ in the text if the user has the cursor placed part way through the text paragraphs, please?

Regards

Santa

Model: Late 2014 retina i7, Yosemite
AppleScript: 2.4
Browser: Safari 600.2.5
Operating System: Other

Hi Santa,

to move the cursor to the end of a text field use this (it assumes that textField is a reference to a NSTextField)


textField's currentEditor's moveToEndOfLine:(missing value)

In my experience, one needs to use the key combo option-return to enter a new line/return character in a multi line text field. This behavior seems consistent across applications.

Isn’t it an option to use an NSTextView instead of an NSTextField? I understand you don’t want markup, auto completion, smart inserts and spelling correction but that can all be turned off. The NSTextView has an NStextContainer, NSTextStorage and NSLayoutManager. The storage’s delegate asks for permission of the editing which enables you to fully control the editing process of an editable text layout.