Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Bash script: move mouse automatically

  1. #1
    Join Date
    Feb 2006
    Beans
    33

    Bash script: move mouse automatically

    Hello.

    I configured my infra-red remote control to power off my monitor using this little script I found somewhere
    Code:
    #!/bin/bash
    
    STATUS=`xset -q | grep "Monitor is" | awk '{print $3}'`
    
    if [ "${STATUS}" = "On" ]
    then
       xset dpms force off
    else
       xset dpms force on
    fi
    exit 0
    It works just swell if I want to turn the monitor off . If I press the power button on my remote again, the monitor turns on (it returns from sleep mode) but remains blank. In order to see my desktop again, I have to either move the mouse or press a key on the keyboard.

    So I was thinking of writing a script that automatically moves the mouse just a tiny little bit and running this script right after xset dpms force on, in the else branch. The problem is that I am clueless when it comes to writing scripts that simulate mouse movements.

    Bottom line: I'm either looking for a script that can move the mouse or some alternative(less goofy) solution to my problem.

    I'd appreciate your help.

    Thanks.

  2. #2
    Join Date
    Feb 2006
    Location
    Vancouver, BC, Canada
    Beans
    318

    Re: Bash script: move mouse automatically

    It would be easier to send a button press event.

    Code:
    xsendkeys Shift_L

  3. #3
    Join Date
    Feb 2006
    Beans
    33

    Re: Bash script: move mouse automatically

    Thanks for your simple solution, mate!

    Works like a charm.

  4. #4
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,285
    Distro
    Kubuntu

    Re: Bash script: move mouse automatically

    Thanks for the post... it gave me a good chuckle.

    It would be awesome to write some code that could move the mouse! I knew what you meant... the mouse "pointer" or "cursor", but to physically move the mouse, that would have been something to see.

    Anyhow, I'm glad you resolved your little problem.

  5. #5
    Join Date
    Feb 2006
    Beans
    33

    Re: Bash script: move mouse automatically

    Actually, the idea for moving the mouse pointer/cursor in order to keep the monitor on, comes from an older xkcd comic:

    http://xkcd.com/196/

  6. #6
    Join Date
    Aug 2006
    Beans
    Hidden!
    Distro
    Ubuntu 6.06

    Re: Bash script: move mouse automatically

    if anyone's interested

    Code:
    xte 'mousermove 1 1'

  7. #7
    Join Date
    Mar 2007
    Location
    Maine
    Beans
    97
    Distro
    Kubuntu 10.04 Lucid Lynx

    Re: Bash script: move mouse automatically

    What do you need installed for the xte and xsendkeys?
    Ubuntu 8.04 Hardy Heron
    BIOSTAR TFORCE 550 Socket AM2 NVIDIA nForce 550 MCP ATX AMD MOBO, AMD Athlon 64 X2 3600+ w/ Arctic Cooling Alpine 64, 3x512MB DDR2 800 OCZ Gold SDRAM, Gigabyte GeForce 7300GT 256MB GDDR2, 160GB SATA 120GB PATA

  8. #8
    Join Date
    Feb 2007
    Location
    The hills of appalachia
    Beans
    966

    Re: Bash script: move mouse automatically

    What do you need installed for the xte and xsendkeys?
    xte is found in the xautomation package

    And I am not sure but I think xsendkeys is found in the lineakd package.
    If you think you're free, there's no escape possible. Ram Dass

  9. #9
    Join Date
    Jul 2010
    Beans
    1

    Re: Bash script: move mouse automatically

    This is quite wonderful. Thanks guys.

  10. #10
    Join Date
    Nov 2005
    Location
    Vienna, Austria
    Beans
    227

    Re: Bash script: move mouse automatically

    I'd like to use this xte thing to combat a screen saver that resists all attempts to be switched off. And it works from the terminal - the mouse moves one pixel to the right and one down. But on a cronjob the mouse pointer won't move.

    Here's the crontab line, with an additional command for debugging:
    */1 * * * * /usr/bin/xte 'mousermove 1 1' && echo 'mouse wiggled!' >> /tmp/mousecron.log
    The cronjob's working, I get the log entry every minute, but the mouse won't move like it does when entering the command in a terminal. Tried root crontab too, to no avail. Anyone?

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •