How to replace the currently selected text in Applescript? How does Devontechnologies WordServices' do it?
You could use an Automator contextual workflow service.


Open Automator select Contextual Workflow

Enter the following settings


Workflow Receives: text
In: Any Applicaition
Check Output replaces selected text

Add the AppleScript Action





The selected text will be in the input variable. It will return the input variable at the end thus replacing the original text with the new text


The workflow can be accessed by selecting text, right clicking, and going to Services.