12

I am looking for a way to click the mouse, as it is in its current location or in a specific location on the screen, after x minutes. Is there any way to do this with a terminal command (preferably with the programs Ubuntu has installed by default)?

1
  • Ubuntu comes with Python, and because Python is the swiss-knife (or is that Perl?). No, Python is the glue. So look here: stackoverflow.com/questions/3545230/…
    – user85164
    Nov 5, 2013 at 2:19

1 Answer 1

20

Yes there is xdotool. xdotool is a automation tool from X11. To install it type

sudo apt-get install xdotool

To click the mouse via terminal command type:

xdotool click <button>

where button is 1 for left mouse button, 2 for middle, 3 for right, 4 for wheel up and 5 for wheel down.

So a click with the left mouse button is:

xdotool click 1

To move the mouse to a specific position on the screen type

xdotool mousemove 120 100

So the mouse is moved 120 pixels right and 100 pixels down from the top left corner of the screen.

If you want to use this in a cron job (to repeat this every x minutes), don't forget to populate the $DISPLAY environment variable in your crontab.

2
  • 2
    Do you know how to run this command inside a desktop (e.g. Mate or Gnome)? For example, if I set this command to a keyboard shortcut in Mate it doesn't do anything. It only works if I execute it at command line.
    – trusktr
    Feb 20, 2014 at 8:01
  • 5
    You need to set the $DISPAY variable. Something like this: DISPLAY=:0 xdotool click 1
    – chaos
    Feb 20, 2014 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.