Tuesday 8 April 2014

xdotool Simple example

xdotool
used in Debian wheezy7,Lxde,openbox;

" What is xdotool? 

This tool lets you simulate keyboard input and mouse activity, move and resize windows, etc. It does this using X11's XTEST extension and other Xlib functions.
Additionally, you can search for windows and move, resize, hide, and modify window properties like the title. If your window manager supports it, you can use xdotool to switch desktops, move windows between desktops, and change the number of desktops. "
                                     -http://www.semicomplete.com/projects/xdotool/
tl;dr
xdotool helps you to automate mouse and keyboard events.

Use cases
# you name it

Example
for example i want to disable my touch-pad on my laptop when im using mouse,so i can  write script to dot it,rather than going and selecting gpointing-device-settings then clicking disable touch-pad .

Steps
#1- download and install xdotool using synaptic package manager or which ever you use.[and gpointing-device-settings if dont have ]

#2-open terminal type "xdotool getmouselocation" ,this returns mouse location in x y coordinates.
#3-open terminal type "/usr/bin/gpointing-device-settings",this opens gpointing-device-settings 

#4-now using step2 check the coordinates of touch-pad button in gpointing-device-settings[make sure to keep the cursor on the touch-pad button and if you cant keep the terminal window active,right click the window title bar and select Layer>keep alawys on top, then move the cursor to the according location]

#5 repeate step4 and location of the following part

#step6-do the same to find xy coordinates of "ok"button

#step7-open texteditor and write the following

#!/bin/bash
/usr/bin/gpointing-device-settings &  
sleep 1
WID=`xdotool search "GPointing Device Settings"` &&
sleep 1
xdotool windowactivate --sync $WID 
sleep 1
xdotool mousemove 451 251 click 1
sleep 1
xdotool mousemove 567 213 click 1
sleep 1
xdotool mousemove 567 213 click 1
sleep 1
xdotool mousemove 912 589 click 1

#step8-save it as touchpadcancel.sh
#step9-Run it[change the files properties to change it to "make it executable",if it cant run by default]
#step10- DONE

Explanation of code
/usr/bin/gpointing-device-settings
>opens gpointing-device-settings
sleep>stop the code execution,so the following code is executed 1by1.

xdotool search "GPointing Device Settings"

>serach for window with tiltle GPointing Device Settings

xdotool windowactivate --sync $WID
>makes the window with title "GPointing Device Settings" active 
xdotool mousemove 451 251 click 1
>move the cursor to x:451 and y:251 and click at the coordinate