Based on my previous article " InDesign Scripting with ScriptUI: How to Move Cursor and Select Text ", let's add a button to play around. The original code looks like this: // --- Last Part of UI (No Panel) --------------------------------------------- function AddCloseButton(w) { w.grpButtons = w.add('group'); w.btnClose = w.grpButtons.add('button {text: "Close"}'); w.btnClose.onClick = function () { w.close(); } } // ------------------------------------------------------- Let me add a button to select a piece of text. Below in in the listener function "TestIt", I don't add the boundary checking . You may try and modify the variables "start" and "end" to go over the boundary. And see what happens. // --- Last Part of UI (No Panel) --------------------------------------------- function AddCloseButton(w) { w.grpButtons = w.add('group'); w.grpButtons.orientation = "column"; ...