I would like to execute a command-line command that activates "click and drag" mouse selection on a single local X11 screen.

The goal is to:

  • get the selected rectangle X and Y coordinates,
  • get the rectangle width and height,
  • output these values to stdout,
  • (optional) draw a selection border while dragging the mouse.
  • Do you mean you want to move the mouse, as in "click and drag", to draw a rectangle on the desktop, and have some program then tell you what its size is?
    – Chindraba
    Feb 27 '17 at 11:12
  • @Gypsy Spellweaver, yes the rectangle can simply be outlines. does not have to be a filled box. I want the size of it ( in pixels ) also.. if it can include the X and Y coordinates on the screen. that would be extra help.
    – user218169
    Feb 27 '17 at 11:19
  • Perhaps soon as the rectangle drawn is complete.. the rectangle can disappear.. and I can return to the command prompt to see the data.
    – user218169
    Feb 27 '17 at 11:20

A simple tool is the import command from ImageMagick. Simply provide an output filename:

$ import /tmp/out.png

and it will grab the mouse and show an appropriate cursor. Press button 1 and drag out a rectangle which will be shown as a wire frame. Let go and the file will be created. You can get the info from this file:

$ identify /tmp/out.png
/tmp/out.png PNG 1515x14 1920x1080+24+15 ...

The rectangle in this example was 1515 by 14 pixels, with top-left offset of 24 and 15 on the screen.