Inserting text at insertion point

I’m trying to insert text right at the insertion point in a text field. I’ve tried this:

someTextField’s insertText_(“some Text”)


set mySelection to someTextField’s selection
mySelection’s insertText_(“some Text”)

No luck.

This works but I don’t want to require assisted devices to be on:

tell application “System Events” to keystroke “some text”

Any help? Thanks in advance!


we’re talking about Cocoa, all tools to manipulate text are included.

NSTextField has a underlying editor class which is able to change the contents.
From your code I assume that you want to replace the selected text with “some Text”.

set textEditor to someTextField's currentEditor()
textEditor's replaceCharactersInRange:textEditor's selectedRange() withString:"some Text"

Fantastic, this is perfect, works great. thanks Stephan.