To replace selected text in an application with a result:

In an application that supports services, select the text you want to run.

Choose the application menu >Services > Script Editor > Get Result of AppleScript.
Script Editor allows applications to treat selected text as a script. In any application that supports the Services menu, you can select text and replace it with the results of an executed script.
Note: For AppleScript to execute the selected text, there must be one or more AppleScript commands that are syntactically correct.
In an application that supports services, select the text you want to run.
Choose the application menu >Services > Script Editor > Get Result of AppleScript.