print #handle, "!selection? selected$" ;

This command returns the highlighted text from the window.  The result will be contained in the variable selected$.