Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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)?

share|improve this question
Ubuntu comes with Python, and because Python is the swiss-knife (or is that Perl?). No, Python is the glue. So look here:… – user85164 Nov 5 '13 at 2:19
up vote 8 down vote accepted

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.

share|improve this answer
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 '14 at 8:01
You need to set the $DISPAY variable. Something like this: DISPLAY=:0 xdotool click 1 – chaos Feb 20 '14 at 15:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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