To run text selected in another application as a script:

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

Choose the application menu >Services > Script Editor > Run as AppleScript.
Script Editor inserts items into the Services menu that allows applications to run selected text as a script. In any application that supports the Services menu, you can select text and have AppleScript run it as a 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 > Run as AppleScript.